-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ERR_MODULE_NOT_FOUND]: Cannot find package 'nanoid' #30363
Comments
This error is related to SWC. Steps to reproduce:
import 'node-html-parser'
Output:
|
See related issue #30393 with a full reproduction, same issue when using highlight.js package. |
In my case, Actual result: [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\test-nextjs\.next\server\pages\_document.js
require() of ES modules is not supported.
require() of C:\test-nextjs\.next\server\pages\_document.js from C:\test-nextjs\.yarn\__virtual__\next-virtual-4abf088994\0\cache\next-npm-12.0.2-canary.8-0c66f38afe-39035a5d0e.zip\node_modules\next\dist\server\require.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename _document.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\test-nextjs\package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1085:13)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.external_module_.Module._load (C:\test-nextjs\.pnp.cjs:13417:14)
at Module.require (internal/modules/cjs/loader.js:957:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.requirePage (C:\test-nextjs\.yarn\__virtual__\next-virtual-4abf088994\0\cache\next-npm-12.0.2-canary.8-0c66f38afe-39035a5d0e.zip\node_modules\next\dist\server\require.js:48:12)
at Object.loadComponents (C:\test-nextjs\.yarn\__virtual__\next-virtual-4abf088994\0\cache\next-npm-12.0.2-canary.8-0c66f38afe-39035a5d0e.zip\node_modules\next\dist\server\load-components.js:56:23)
at DevServer.findPageComponents (C:\test-nextjs\.yarn\__virtual__\next-virtual-4abf088994\0\cache\next-npm-12.0.2-canary.8-0c66f38afe-39035a5d0e.zip\node_modules\next\dist\server\next-server.js:1193:63)
at DevServer.findPageComponents (C:\test-nextjs\.yarn\__virtual__\next-virtual-4abf088994\0\cache\next-npm-12.0.2-canary.8-0c66f38afe-39035a5d0e.zip\node_modules\next\dist\server\dev\next-dev-server.js:643:26)
at async DevServer.renderErrorToResponse (C:\test-nextjs\.yarn\__virtual__\next-virtual-4abf088994\0\cache\next-npm-12.0.2-canary.8-0c66f38afe-39035a5d0e.zip\node_modules\next\dist\server\next-server.js:1663:26) {
code: 'ERR_REQUIRE_ESM'
} Versions:next: 12.0.2-canary.8 Maybe next.js actually isn't fully compatible with ESM (source) FYI @timneutkens Edit 1Same behavior using Edit 2Next.js doesn't support |
FYI, while this gets fixed I was able to get unblocked by adding |
Which package? |
I think this is a Node bug. Meet it with only node app. |
@balazsorban44 @timneutkens This issue can be closed. |
Please verify that your issue can be recreated with Why was this issue marked with the
|
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
12.0.0
What version of Node.js are you using?
14.18.0
What browser are you using?
Chrome
What operating system are you using?
Windows
How are you deploying your application?
next start
Describe the Bug
Importing package 'nanoid' causes error:
package.json dependencies:
"nanoid": "^3.1.30"
Expected Behavior
Successful import
To Reproduce
Occurs when:
yarn version 3.1.0 [berry] - without dir node_modules (only /.yarn/cache) and PnP
Minimal reproduce in https://github.com/mufteev/BUG-debugging-with-new-line-in-template-literals
The text was updated successfully, but these errors were encountered: