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
{{ message }}
Repository navigation
module import errors follow different logic than importing #51216
import { four } from 'foo.mjs';
console.log(four());
File node_modules/foo.mjs:
export function four() {
return 4;
}
Result:
node:internal/process/esm_loader:34
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'foo.mjs' imported from /usr/local/google/home/walkingeyerobot/nodetest/main.mjs
Did you mean to import foo.mjs?
at packageResolve (node:internal/modules/esm/resolve:853:9)
at moduleResolve (node:internal/modules/esm/resolve:910:20)
at defaultResolve (node:internal/modules/esm/resolve:1130:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
at link (node:internal/modules/esm/module_job:84:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js v21.4.0
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior? Why is that the expected behavior?
I would expect one of:
(preferred) The module loads, and the number 4 is printed
The error message does not suggest to me to do exactly what I'm already doing
What do you see instead?
The error message tries to be helpful and suggests I try to import from foo.mjs, but that's exactly what I'm already doing. It seems like node can see there is a foo.mjs to import when printing an error message but not when doing the actual import. The error messaging and the importing should follow the same logic so as to give helpful error messages.
This doesn't work; foo.mjs is inside the node_modules folder
The imported path is wrong.
If that is the case, the error message should reflect that. Instead, the error message suggests that I import foo.mjs when I'm already importing foo.mjs.
If the code is wrong, then the error message suggestion is wrong as well. Error messages shouldn't suggest bad code. Hence the bug.
Activity
Stebinraj commentedon Dec 19, 2023
import { four } from "./foo.mjs";
console.log(four());
The imported path is wrong.
walkingeyerobot commentedon Dec 19, 2023
This doesn't work;
foo.mjsis inside thenode_modulesfolderIf that is the case, the error message should reflect that. Instead, the error message suggests that I import
foo.mjswhen I'm already importingfoo.mjs.If the code is wrong, then the error message suggestion is wrong as well. Error messages shouldn't suggest bad code. Hence the bug.
ionicmc-js commentedon Dec 19, 2023
Hello im a new contributor! ill get to finding the source of the bug and fix it :)
esm: fix hint on invalid module specifier
esm: fix hint on invalid module specifier
esm: fix hint on invalid module specifier