Closed
Description
Version
16.13.0
Platform
Microsoft Windows NT 10.0.19043.0 x64
Subsystem
No response
What steps will reproduce the bug?
- create a file to run the code, e.g.
server.js
:
import { userZero } from './#user/user0.js'
console.log(userZero)
- create
package.json
:
{
"type": "module"
}
- create a folder starting with
#
(probably not the only unsupported character), e.g.#user
- create a file in this folder, e.g.
user0.js
:
export const userZero = 'This is a user.'
How often does it reproduce? Is there a required condition?
Node.js always throws an unconditional error during the import.
What is the expected behavior?
It should log the string.
What do you see instead?
PS D:\issue> node .\server.js
node:internal/process/esm_loader:94
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'D:\issue\' is not supported resolving ES modules imported from D:\issue\server.js
Did you mean to import ../#user/user0.js?
at new NodeError (node:internal/errors:371:5)
at finalizeResolution (node:internal/modules/esm/resolve:412:17)
at moduleResolve (node:internal/modules/esm/resolve:932:10)
at defaultResolve (node:internal/modules/esm/resolve:1044:11)
at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36) {
code: 'ERR_UNSUPPORTED_DIR_IMPORT',
url: 'file:///D:/issue/#user/user0.js'
}
Additional information
npm -v
: 8.1.0- It does not matter whether a relative or absolute path is used, although the error is slightly different
- Trying to escape
\
the#
does not work - If you remove the
#
, it works as expected - Node.js seems to think I want to import a directory before the
#
, yet is aware of the rest of the full path...? - The suggested solution ("Did you mean to import ...") is complete nonsense in this case
- I couldn't find a list if unsupported characters for
import module-names
, so I have to assume there is none, which would mean that every character should be supported, especially since it's just a string pointing to a file - Thought I was going crazy when this simple import refused to work, so I made sure everything else works fine multiple times...
Edit: Typo
Activity