nuxt: Nitro externalized package has incorrect main entry point
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)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 7
- Comments: 19 (4 by maintainers)
Commits related to this issue
- fix: nitro bug (https://github.com/nuxt/framework/issues/7105) — committed to 6starlong/starlong-blog by 6starlong 2 years ago
- fix: nitro bug (nuxt/framework/issues/7105) — committed to 6starlong/starlong-blog by 6starlong 2 years ago
- fix: nitro bug (https://github.com/nuxt/framework/issues/7105) — committed to 6starlong/starlong-blog by 6starlong 2 years ago
- fix: nitro bug (https://github.com/nuxt/framework/issues/7105) — committed to 6starlong/starlong-blog by 6starlong 2 years ago
I am seeing this issue still with rc12. The below error is generated for multiple packages:
Then at
nuxi preview:npm ls parse5:Same happens for packages
pako,uuid,readable-stream,@xmldom/xmldomandtslib. Possibly these changed their module formats between major versions, and that is throwing the compiler off?@danielroe Hey, It seems like the issue isn’t resolved (RC 11). This time the
semver.jsisn’t generated. I’ve updated my reproduction.Same issue here with: https://www.npmjs.com/package/jose
Server compilation generates /path/to/project/.output/server/node_modules/jose/dist/node/esm/index.js
This happens for me with a few packages,
semver,lru-cache,jws,yallistandjwa.I understand the issue is not related to specific packages, but I wanted to post them here anyway for other people that encounter the same issue. I’m using the edge release (currently 3.0.0-rc.13-27781436.1f6b3be).
Even after this fix, overriding an older version can provoke error in case of using another module that depends on overrided version, so forcing newer version can lead to incompatibility problems (googleapis and jsonwebtoken use jwa with different versions for example) maybe adding an option to disable trace for nested modules would be temporarily a solution
This is fixed in 3.1. https://github.com/unjs/nitro/pull/782