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.

Module not found: ESM packages (/path/to/app/page.js) need to be imported.

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Tue Sep 13 07:51:46 UTC 2022
Binaries:
  Node: 18.12.0
  npm: 8.19.2
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 13.0.0
  eslint-config-next: 12.3.1
  react: 18.2.0
  react-dom: 18.2.0

warn - Latest canary version not detected, detected: “13.0.0”, newest: “12.3.2-canary.43”. Please try the latest canary version (npm install next@canary) to confirm the issue still exists before creating a new issue. Read more - https://nextjs.org/docs/messages/opening-an-issue

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Here is the error output when I run npm run dev or build:

Module not found: ESM packages (/path/to/app/page.js) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals

https://nextjs.org/docs/messages/module-not-found

Could someone give me direction since I don’t know where to start with this bug?

I have enabled the novel app directory (experimental: { appDir: true }) and tried to put page.js and layout.js files in it.

Expected Behavior

Load page.js and layout.js properly.

Link to reproduction

To Reproduce

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
huozhicommented, Nov 10, 2022

@vladshcherbin Thanks for confirmation, I’ll close this issue as resolved.

@schickling it’s related to the esm package resolving, it’s caused by a different issue. will track yours in https://github.com/vercel/next.js/issues/42534 as duplicate issue

1reaction
vladshcherbincommented, Oct 29, 2022

Using *.jsx as file extension also resolves the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Import ES module in Next.js ERR_REQUIRE_ESM
I got it working by dynamically importing ky before using it but it's not elegant nor efficient. const handleFormSubmit = async (event) =>...
Read more >
module-not-found - Next.js
When importing a module from npm this module has to be installed locally. For example when importing the swr package: import useSWR from...
Read more >
Modules: Packages | Node.js v19.3.0 Documentation
It can load JSON modules, but an import assertion is required. ... If a package.json file does not have a "type" field, .js...
Read more >
esm - npm
esm. 3.2.25 • Public • Published 4 years ago ... esm is the world's most advanced ECMAScript module loader. This fast, production ready, ......
Read more >
Using ECMAScript modules (ESM) with Node.js
CommonJS modules, though ubiquitous thanks to Node.js, are not ... along with Node: CommonJS is already a module system, and ESM has to...
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