framework icon indicating copy to clipboard operation
framework copied to clipboard

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.output/server/node_modules/node-fetch-native/dist/polyfill.mjs'

Open michealroberts opened this issue 2 years ago • 3 comments

Environment

Nuxi 3.0.0-rc.12-27729267.0640a6c


  • Operating System: Darwin
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.12-27729267.0640a6c
  • Nitro Version: 0.5.4-27726613.640c2b7
  • Package Manager: [email protected]
  • Builder: vite
  • User Config: ssr, app, css, buildModules, build, nitro, runtimeConfig
  • Runtime Modules: -
  • Build Modules: [email protected]

Reproduction

I can provide a reproduction if required ... but this seems to be happening on both rc-11, rc-12 and latest ...

Describe the bug

After running pnpm run build on my project, I am seeing the following stack trace when starting the node server (either using node ./server/index.mjs or pnpm preview) ...

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/michael/Developer/observerly/sirius/apps/www/.output/server/node_modules/node-fetch-native/dist/polyfill.mjs' imported from /Users/michael/Developer/observerly/sirius/apps/www/.output/server/index.mjs
    at new NodeError (node:internal/errors:371:5)
    at finalizeResolution (node:internal/modules/esm/resolve:418:11)
    at moduleResolve (node:internal/modules/esm/resolve:983:10)
    at defaultResolve (node:internal/modules/esm/resolve:1080:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:530:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:251:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:79:40)
    at link (node:internal/modules/esm/module_job:78:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Additional context

No response

Logs

No response

michealroberts avatar Sep 21 '22 16:09 michealroberts

Upstream issue created:

  • https://github.com/unjs/nitro/issues/526

issue-up[bot] avatar Sep 21 '22 21:09 issue-up[bot]

You can workaround this issue for now by ensuring you have only one version of node-fetch-native in your package lockfile. (The issue is a regression in nitro's traced externals which ignores the polyfill from a lower version in parent directory in favour of other files in a sub dependency of nitro.)

cc: @pi0

danielroe avatar Sep 21 '22 21:09 danielroe

Started to have same error recently.

smakhtin avatar Sep 22 '22 10:09 smakhtin

Here's a minimal reproduction: https://stackblitz.com/edit/github-1nqt6s.

danielroe avatar Sep 23 '22 12:09 danielroe

Hi @danielroe So what is the specific workaround? Do we need to add node-fetch-native to the package.json of our Nuxt project at the version specified in your repro?

michealroberts avatar Sep 26 '22 12:09 michealroberts

Yes; you can run npm i node-fetch-native.

danielroe avatar Sep 26 '22 12:09 danielroe

Ok cool, so just to confirm, that doesn't fix the issue for me, unfortunately.

michealroberts avatar Sep 26 '22 12:09 michealroberts

The issue is multiple versions installed rather than a specific version number; check your lockfile to see what they are and why. You may also be able to resolve with npm overrides.

danielroe avatar Sep 26 '22 12:09 danielroe

For me it helped to remove yarn.lock and generate new one from scratch.

smakhtin avatar Sep 26 '22 12:09 smakhtin

Ok, looks like ohmyfetch was the culprit, I have bumped this version and seems to be good.

michealroberts avatar Sep 26 '22 12:09 michealroberts

Reopening until we resolve in nitropack - you can follow https://github.com/unjs/nitro/pull/529.

danielroe avatar Sep 26 '22 13:09 danielroe

I'm just now running into this issue using nuxt bridge "@nuxt/bridge": "npm:@nuxt/bridge-edge@^3.0.0-27747000.69db93e" (latest as of this writing). I've bumped ohmyfetch and tried to install just node-fetch-native to no avail

michaelschofield avatar Oct 19 '22 03:10 michaelschofield