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
TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module "#/file2.js" is not a valid internal imports specifier name
How often does it reproduce? Is there a required condition?
This happens every time a key/value pair in imports has a forward slash (/) immediately following the pound sign (#).
What is the expected behavior? Why is that the expected behavior?
I would expect that file1.js is able to resolve file2.js with the specified alias. The documentation does not specify that this is an invalid setting.
What do you see instead?
TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module "#/file2.js" is not a valid internal imports specifier name
Additional information
There is no indication that the above configuration would not work based on the documentation. Indeed, even WebStorm's IntelliSense resolves this alias as if it would work.
Of course, setting the alias to to "#src/*": "./*" and changing file1.js to use import number from '#src/file2.js'; would work. However, I feel that would be inelegant. Imagine we have a project structure where all the files of interest are in src/, such as the following:
Keeping the current restriction is not much of a problem if the main documentation includes some warning or if the error message for using #/ was unique. As it stands, Node throws the generic error that applies to any failed module resolution and gives no indication that #/ itself is invalid.
RedYetiDev
added
esm
Issues and PRs related to the ECMAScript Modules implementation.
loaders
Issues and PRs related to ES module loaders
labels
Apr 28, 2024
Version
v20.11.1
Platform
Microsoft Windows NT 10.0.22631.0 x64
Subsystem
npm
What steps will reproduce the bug?
package.json
that specifies the following inimports
:node file1.js
How often does it reproduce? Is there a required condition?
This happens every time a key/value pair in
imports
has a forward slash (/
) immediately following the pound sign (#
).What is the expected behavior? Why is that the expected behavior?
I would expect that
file1.js
is able to resolvefile2.js
with the specified alias. The documentation does not specify that this is an invalid setting.What do you see instead?
Additional information
There is no indication that the above configuration would not work based on the documentation. Indeed, even WebStorm's IntelliSense resolves this alias as if it would work.
Of course, setting the alias to to
"#src/*": "./*"
and changingfile1.js
to useimport number from '#src/file2.js';
would work. However, I feel that would be inelegant. Imagine we have a project structure where all the files of interest are insrc/
, such as the following:It would be much cleaner to be able to import these files with minimal boilerplate, such as:
...as opposed to having some needless additional text or specifying each directory as an alias:
The text was updated successfully, but these errors were encountered: