question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use dynamic import with esm package

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
timneutkenscommented, Jan 13, 2022

Thanks for checking and reporting back 🙏

0reactions
balazsorban44commented, Feb 13, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found