Skip to content
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

Closed
mufteev opened this issue Oct 26, 2021 · 10 comments
Closed

[ERR_MODULE_NOT_FOUND]: Cannot find package 'nanoid' #30363

mufteev opened this issue Oct 26, 2021 · 10 comments
Labels
bug Issue was opened via the bug report template. please verify canary The issue should be verified against next@canary. It will be closed after 30 days of inactivity

Comments

@mufteev
Copy link

mufteev commented Oct 26, 2021

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:

error - unhandledRejection: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'nanoid' imported from .next\server\pages\datasets\catalog\[catalog_id].js
Did you mean to import nanoid-npm-3.1.30-58cf6fe7ec-276d0d4b0c.zip/node_modules/nanoid/index.cjs?

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

  • yarn dev
  • yarn build

Minimal reproduce in https://github.com/mufteev/BUG-debugging-with-new-line-in-template-literals

@mufteev mufteev added the bug Issue was opened via the bug report template. label Oct 26, 2021
@ijjk ijjk added the please add a complete reproduction The issue lacks information for further investigation label Oct 26, 2021
@rtritto
Copy link

rtritto commented Oct 26, 2021

This error is related to SWC.
Same problem with latest version 4.0.0 of node-html-parser dependency.
Correctly work with previous version 3.1.0 or using Babel.

Steps to reproduce:

  1. yarn init -y
  2. yarn set version berry
  3. yarn add next react react-dom node-html-parser
  4. Create pages/index.js
import 'node-html-parser'
  1. yarn next
  2. Go to localhost:3000

Output:

unhandledRejection: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'node-html-parser' imported from C:\test-nextjs\.next\server\pages\index.js
Did you mean to import node-html-parser-npm-5.0.0-719fdf923f-7fa49cf47b.zip/node_modules/node-html-parser/dist/index.js?

@mward-sudo
Copy link
Contributor

See related issue #30393 with a full reproduction, same issue when using highlight.js package.

@mufteev
Copy link
Author

mufteev commented Oct 27, 2021

Update reference on minimal reproduce, the principle is similar to #30393.

Minimal reproduction is combined with #30435.

@ijjk

@rtritto
Copy link

rtritto commented Oct 29, 2021

In my case, node-html-parser is in ESM, so I added "type": "module" in package.json and pnpEnableEsmLoader: true to yarnrc.yml (default value is false but maybe is optional because yarn, on install, autogenerate .pnp.loader.mjs).

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
yarn: 3.1.0

Maybe next.js actually isn't fully compatible with ESM (source)

FYI @timneutkens


Edit 1

Same behavior using nanoid or highlight.js.

Edit 2

Next.js doesn't support "type": "module" (yet) (source)

@timneutkens timneutkens added Output (export/standalone) Related to the the output option in `next.config.js`. and removed please add a complete reproduction The issue lacks information for further investigation labels Nov 17, 2021
@timneutkens timneutkens added area: Yarn PnP / pnpm and removed Output (export/standalone) Related to the the output option in `next.config.js`. labels Nov 18, 2021
@ericvera
Copy link

FYI, while this gets fixed I was able to get unblocked by adding experimental: { esmExternals: false }, to next.config.js as suggested in #30873.

@kmvan
Copy link

kmvan commented Apr 14, 2022

FYI, while this gets fixed I was able to get unblocked by adding experimental: { esmExternals: false }, to next.config.js as suggested in #30873.

Which package?

@kmvan
Copy link

kmvan commented Apr 14, 2022

I think this is a Node bug. Meet it with only node app.

@rtritto
Copy link

rtritto commented May 2, 2022

@balazsorban44 @timneutkens This issue can be closed.

@jankaifer jankaifer added the please verify canary The issue should be verified against next@canary. It will be closed after 30 days of inactivity label Jan 16, 2023
@github-actions
Copy link
Contributor

Please verify that your issue can be recreated with next@canary.

Why was this issue marked with the please verify canary label?

We noticed the provided reproduction was using an older version of Next.js, instead of canary.

The canary version of Next.js ships daily and includes all features and fixes that have not been released to the stable version yet. You can think of canary as a public beta. Some issues may already be fixed in the canary version, so please verify that your issue reproduces by running npm install next@canary and test it in your project, using your reproduction steps.

If the issue does not reproduce with the canary version, then it has already been fixed and this issue can be closed.

How can I quickly verify if my issue has been fixed in canary?

The safest way is to install next@canary in your project and test it, but you can also search through closed Next.js issues for duplicates or check the Next.js releases. You can also use the GitHub template (preferred), or the CodeSandbox or StackBlitz templates to create a reproduction with canary from scratch.

My issue has been open for a long time, why do I need to verify canary now?

Next.js does not backport bug fixes to older versions of Next.js. Instead, we are trying to introduce only a minimal amount of breaking changes between major releases.

What happens if I don't verify against the canary version of Next.js?

An issue with the please verify canary that receives no meaningful activity (e.g. new comments that acknowledge verification against canary) will be automatically closed and locked after 30 days.

If your issue has not been resolved in that time and it has been closed/locked, please open a new issue, with the required reproduction, using next@canary.

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the 👍 reaction on the topmost comment (please do not comment "I have the same issue" without repro steps). Then, we can sort issues by votes to prioritize.

I think my reproduction is good enough, why aren't you looking into it quicker?

We look into every Next.js issue and constantly monitor open issues for new comments.

However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. please verify canary The issue should be verified against next@canary. It will be closed after 30 days of inactivity
Projects
None yet
Development

No branches or pull requests

8 participants