Closed dakhnod closed 1 month ago
Two questions:
Does this also occur with require? Is this REPL specific, or does it occur with files?
> const odd = require ('is-odd');
Uncaught:
Error: Cannot find module '/app/node_modules/is-odd/index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (node:internal/modules/cjs/loader:482:19)
at Module._findPath (node:internal/modules/cjs/loader:765:18)
at Module._resolveFilename (node:internal/modules/cjs/loader:1205:27)
at Module._load (node:internal/modules/cjs/loader:1045:27)
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:215:24)
at Module.require (node:internal/modules/cjs/loader:1304:12)
at require (node:internal/modules/helpers:123:16) {
code: 'MODULE_NOT_FOUND',
path: '/app/node_modules/is-odd/package.json',
requestPath: 'is-odd'
}
require works properly.
Yep, also occurs in files:
root@18f9f8c95d94:/app# node app.mjs
node:internal/modules/esm/resolve:210
const resolvedOption = FSLegacyMainResolve(packageJsonUrlString, packageConfig.main, baseStringified);
^
Error: Cannot find package '/app/node_modules/is-odd/package.json' imported from /app/app.mjs
at legacyMainResolve (node:internal/modules/esm/resolve:210:26)
at packageResolve (node:internal/modules/esm/resolve:829:14)
at moduleResolve (node:internal/modules/esm/resolve:915:18)
at defaultResolve (node:internal/modules/esm/resolve:1132:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:526:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:249:38)
at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:484:36)
at TracingChannel.tracePromise (node:diagnostics_channel:337:14)
at ModuleLoader.import (node:internal/modules/esm/loader:483:21) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js v22.4.1
I'm not able to reproduce screen-capture.webm
you need to delete the index.js
Oh, okay
+ repro-exists
:
$ npm i is-odd
added 2 packages in 329ms
$ rm node_modules/is-odd/index.js
$ node
Welcome to Node.js v22.4.1.
Type ".help" for more information.
> await import('is-odd')
Uncaught:
Error: Cannot find package '/node_modules/is-odd/package.json' imported from /repl
at legacyMainResolve (node:internal/modules/esm/resolve:210:26)
at packageResolve (node:internal/modules/esm/resolve:829:14)
at moduleResolve (node:internal/modules/esm/resolve:915:18)
at defaultResolve (node:internal/modules/esm/resolve:1132:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:526:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:249:38)
at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:484:36)
at TracingChannel.tracePromise (node:diagnostics_channel:337:14) {
code: 'ERR_MODULE_NOT_FOUND'
}
>
So...does this confirm my description?
Yup :-)
@nodejs/loaders
Note that the message was never precisely correct in ESM. Behavior changed between Node.js 20.4.0 and 20.5.0.
In v20.4.0, the message was:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '/XXX/node_modules/is-odd/' imported from /XXX/test.js
I believe this is an edge case that has not been covered. This might be the commit that might have introduced it https://github.com/nodejs/node/commit/a2a8e31cbc441cd2b513227be09d90568aa77b5a, released in Node v20.5.0 cc @H4ad
I forgot to translate correctly the path fileURLToPath(new URL('.', packageJSONUrl)), fileURLToPath(base))
.
I will try open a PR soon.
Version
v20.10.0 up to v22.4.1
Platform
Subsystem
No response
What steps will reproduce the bug?
npm install is-odd
node_modules/is-odd/index.js
node
await import("is-odd")
-> Should yield this message: