error in import #52048
Replies: 2 comments
-
Just in case anybody still runs into this, I recommend checking out this Stackoverflow answer (https://stackoverflow.com/questions/76591038/module-not-found-esm-packages-supports-color-need-to-be-imported-use-import) |
Beta Was this translation helpful? Give feedback.
-
This error occurs because an ESM package (like 'supports-color') is used with 'require', but these libraries should be 'imported'. In newer versions of Next.js and Node.js, ESM is supported by default, but you need to make sure that all packages used are ESM compatible. I will tell you several ways to solve it, try it Change to import: If you use require, change it to import. For example: // Before // After Update packages: If you have an old package that is not compatible with ESM, you can check if there is a newer version of that package that is compatible or not. Setting next.config.js: If the above changes don't work, you can set next.config.js to load these packages as CommonJS.
This setting makes Next.js use require instead of import and temporarily fixes the problem. |
Beta Was this translation helpful? Give feedback.
-
Module not found: ESM packages (supports-color) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals idk how to fix this error could somoene help me with it
Beta Was this translation helpful? Give feedback.
All reactions