How to correctly import Icons to my "components" subfolder #3874
-
I have started a project based on the quickstart that uses create-next-app. I have created a src folder on the root directory and under that a "components" folder. In my component I want to load Icons. I am trying to load them from their respective esm folder but i get error "cannot use import statement outside a module". New to this sorry for the basic question |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hey @evanTheTerribleWarrior! 👋 I'm Dosu, your friendly neighborhood bot here to help with bugs, answer questions, and guide you on your journey to becoming a contributor while we wait for a human maintainer to chime in. I'm diving into your icon import issue and will get back to you with a detailed answer shortly. Stay tuned! |
Beta Was this translation helpful? Give feedback.
-
Disclaimer: This is a very experimental bot using OpenAI's GPT-4. The answers may not be correct, a human will review the answer and update it if necessary. Yes, you are encountering an issue because Jest, the testing framework, often has trouble with the ES Modules (ESM) version of Paste Icons. As mentioned in the Paste documentation, Jest prefers the CommonJS (CJS) version of modules. However, there's a way to configure Jest to correctly handle the ESM versions of Paste Icons, which would allow you to continue using them. You need to add a configuration to your // jest.config.js
{
"transformIgnorePatterns": [
"/node_modules/@twilio-paste/icons/.*"
]
} This configuration will instruct Jest to ignore transforming the Paste Icons module, thus allowing you to import icons from their For more information, you can refer to the Jest documentation on If you continue to experience issues, an alternative workaround, as suggested in the Paste documentation, is to change your icon imports to be from For further details, you can visit the Paste documentation discussion on this topic: Jest fails to import paste icons. Remember, configuring Jest correctly should allow you to use the ESM icons without issues. I also did a search, and I managed to find these other Discussions that might be similar or related to your question. Give them a read to see if they answer your question. If they do, head back here and update this discussion and mark it as answered, pointing others to the related discussion:
|
Beta Was this translation helpful? Give feedback.
-
Actually i will use the cjs version of the icons which works fine. Closing this |
Beta Was this translation helpful? Give feedback.
Actually i will use the cjs version of the icons which works fine. Closing this