Can't use dynamic import with esm package
See original GitHub issueWhat version of Next.js are you using?
12
What version of Node.js are you using?
12.22.0
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
next start
Describe the Bug
Tried to use esm package with dynamic import, It throws this error
Module not found: ESM packages (@package-name) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals
45 | () =>
46 | import("@package-name"),
> 47 | {
| ^
48 | ssr: false,
49 | }
50 | );
Expected Behavior
To Reproduce
Try to dynamic import a esm package i.e. type module in package.json
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:7 (2 by maintainers)
Top Results From Across the Web
How to Dynamically Import ECMAScript Modules
You can import modules dynamically if you use import as a function — import(pathToModule) — a feature available starting ES2020.
Read more >Importing JSX with ESM Dynamic Imports in Node.js
I was able to import JSX in my ESM-only project by: ... I was then able to successfully use const component = await...
Read more >How to Bypass ES Modules Errors in Next.js with Dynamic ...
We'll see how we can fix it with dynamic imports in Next. js. Take a look at the error above so that you're...
Read more >ES2020: `import()` – dynamically importing ES modules - 2ality
It enables dynamic loading of ECMAScript modules and is explained in this blog post.
Read more >ECMAScript modules | Node.js v19.3.0 Documentation
ECMAScript modules are the official standard format to package JavaScript code for reuse. Modules are defined using a variety of import and export ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for checking and reporting back 🙏
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.