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.

Nitro externalized package has incorrect main entry point

See original GitHub issue

Environment


  • Operating System: Linux
  • Node Version: v18.7.0
  • Nuxt Version: 3.0.0-rc.8
  • Package Manager: pnpm@7.9.0
  • Builder: vite
  • User Config: modules
  • Runtime Modules: @nuxt/image-edge@1.0.0-27657146.da85542
  • Build Modules: -

Reproduction

https://github.com/mahdiboomeri/nuxt3-externalized-issue

Describe the bug

When using jsonwebtoken with @nuxt/image which both depend on semver package, on the build step nitro tries to use the latest version. In the server bundle main entry of semver’s package.json points to index.js but the index file is semver.js.

Additional context

The reproduction uses rc8 but I also tested the issue with the edge channel.

Logs

# in the build step
WARN  Multiple major versions of package semver are being externalized. Picking latest version.                        14:58:38
  - /path/to/project/nuxt-semver-issue/node_modules/.pnpm/jsonwebtoken@8.5.1/node_modules/semver@5.7.1
  - /path/to/project/nuxt-semver-issue/node_modules/.pnpm/sharp@0.30.7/node_modules/semver@7.3.7

# when running node .output/server/index.mjs  
[nuxt] [request error] [unhandled] [500] Cannot find module '/path/to/project/nuxt-semver-issue/.output/server/node_modules/semver/index.js'. Please verify that the package.json has a valid "main" entry
  at tryPackage (node:internal/modules/cjs/loader:364:19)  
  at Module._findPath (node:internal/modules/cjs/loader:577:18)  
  at Module._resolveFilename (node:internal/modules/cjs/loader:942:27)  
  at Module._load (node:internal/modules/cjs/loader:804:27)  
  at Module.require (node:internal/modules/cjs/loader:1022:19)  
  at require (node:internal/modules/cjs/helpers:102:18)  
  at Object.<anonymous> (./.output/server/node_modules/jsonwebtoken/lib/psSupported.js:1:14)  
  at Module._compile (node:internal/modules/cjs/loader:1120:14)  
  at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)  
  at Module.load (node:internal/modules/cjs/loader:998:32)

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:6
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
pixelsparkcommented, Oct 19, 2022

I am seeing this issue still with rc12. The below error is generated for multiple packages:

 WARN  Multiple major versions of package parse5 are being externalized. Picking latest version:                                                        14:37:18

  - /xxx/node_modules/parse5@5.1.1
  + /xxx/node_modules/parse5-htmlparser2-tree-adapter/node_modules/parse5@6.0.1

Then at nuxi preview:

Nuxi 3.0.0-rc.12                                                                                                                                        14:37:23
ℹ Node.js version: 18.10.0                                                                                                                              14:37:23
ℹ Preset: node-server                                                                                                                                   14:37:23
ℹ Working dir: .output                                                                                                                                  14:37:23
ℹ Loading .env. This will not be loaded when running the server in production.                                                                          14:37:23
ℹ Starting preview command: node ./server/index.mjs                                                                                                     14:37:23
                                                                                                                                                        14:37:23
node:internal/modules/cjs/loader:393
      const err = new Error(
                  ^

Error: Cannot find module '/xxx/.output/server/node_modules/parse5/lib/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:393:19)
    at Module._findPath (node:internal/modules/cjs/loader:606:18)
    at Module._resolveFilename (node:internal/modules/cjs/loader:971:27)
    at Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1051:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/xxx/.output/server/node_modules/cli-highlight/dist/index.js:30:27)
    at Module._compile (node:internal/modules/cjs/loader:1149:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1203:10)
    at Module.load (node:internal/modules/cjs/loader:1027:32) {
  code: 'MODULE_NOT_FOUND',
  path: '/xxx/.output/server/node_modules/parse5/package.json',
  requestPath: 'parse5'
}

Node.js v18.10.0

 ERROR  Command failed with exit code 1: node ./server/index.mjs                                                                                        14:37:23

  at makeError (node_modules/nuxi/dist/shared/nuxi.bc8d057a.mjs:619:11)
  at handlePromise (node_modules/nuxi/dist/shared/nuxi.bc8d057a.mjs:1026:26)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async Object.invoke (node_modules/nuxi/dist/chunks/preview.mjs:63:5)
  at async _main (node_modules/nuxi/dist/cli.mjs:50:20)

npm ls parse5:

xxx @ /xxx
└─┬ typeorm@0.3.10
  └─┬ cli-highlight@2.1.11
    ├─┬ parse5-htmlparser2-tree-adapter@6.0.1
    │ └── parse5@6.0.1
    └── parse5@5.1.1

Same happens for packages pako, uuid, readable-stream, @xmldom/xmldom and tslib. Possibly these changed their module formats between major versions, and that is throwing the compiler off?

3reactions
mahdiboomericommented, Sep 29, 2022

@danielroe Hey, It seems like the issue isn’t resolved (RC 11). This time the semver.js isn’t generated. I’ve updated my reproduction.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Supercharged GitHub Experience · Volta - Volta.Net
`nuxi prepare` yields incorrect type definitions in target folder's `.nuxt`. enhancement ... Nitro externalized package has incorrect main entry point.
Read more >
Untitled
Brakhet, Impronte digitali uguali, Karin roepke atriz, The beat is mine various ... 5 vaxt namaz vaxtlari 2012, Entry point not found exception...
Read more >
Untitled
Hell is for children pat, Demo 1 intro, Fidget bands for chairs, Medicine from ... Enventis cable packages, Braided bracelets by john hardy,...
Read more >
Change log for 4.6.50
Infof #526 · Bug 1868324: oc logout should make the token invalid #521 ... Bug 1894195: Operator should use entrypoint script #633 ...
Read more >
Untitled
Consideration is valid unless it is, Wire color code, V8 vantage cover? ... I9080, Name of main rec, Salariu parlamentar 2012, El debate...
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