You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Linux dakhnod 6.5.0-10043-tuxedo #47 SMP PREEMPT_DYNAMIC Tue Jun 4 14:29:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
run npm install is-odd
delete node_modules/is-odd/index.js
start node
run await import("is-odd")
-> Should yield this message:
Uncaught:
Error: Cannot find package '/app/node_modules/is-odd/package.json' imported from /app/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'
}
complaining about not being able to find package.json, although that file exists.
What is really missing is index.js, since we deleted it.
How often does it reproduce? Is there a required condition?
always
What is the expected behavior? Why is that the expected behavior?
It would help if node reported about the really missing index.js, not the existing package.json
What do you see instead?
Node complains about not being able to find package.json, although that one clearly 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'
}
>
I believe this is an edge case that has not been covered.
This might be the commit that might have introduced it a2a8e31, released in Node v20.5.0
cc @H4ad
Activity
avivkeller commentedon Jul 11, 2024
Two questions:
Does this also occur with require?
Is this REPL specific, or does it occur with files?
dakhnod commentedon Jul 11, 2024
require works properly.
Yep, also occurs in files:
avivkeller commentedon Jul 11, 2024
I'm not able to reproduce
screen-capture.webm
dakhnod commentedon Jul 11, 2024
you need to delete the index.js
avivkeller commentedon Jul 11, 2024
Oh, okay
avivkeller commentedon Jul 11, 2024
+
repro-exists:dakhnod commentedon Jul 11, 2024
So...does this confirm my description?
avivkeller commentedon Jul 11, 2024
Yup :-)
targos commentedon Jul 11, 2024
@nodejs/loaders
targos commentedon Jul 11, 2024
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:
marco-ippolito commentedon Jul 15, 2024
I believe this is an edge case that has not been covered.
This might be the commit that might have introduced it a2a8e31, released in Node v20.5.0
cc @H4ad
H4ad commentedon Jul 15, 2024
I forgot to translate correctly the path
fileURLToPath(new URL('.', packageJSONUrl)), fileURLToPath(base)).I will try open a PR soon.