Closed
Description
- Version: v14.4.0
- Platform: The node:14 docker container
What steps will reproduce the bug?
I'm creating a file called foo
(without extension) at /app/bin/foo
. I have a /app/package.json
file with "type": "module",
.
The foo
file has a #!/usr/bin/env node
shebang and /app/bin
is in the PATH
.
Now I want to run foo
.
What is the expected behavior?
I would expect node to execute the file as ESM because of the "type": "module",
in the parents folder package.json
.
What do you see instead?
I get the following error:
internal/modules/run_main.js:54
internalBinding('errors').triggerUncaughtException(
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /app/bin/foo
at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:65:15)
at Loader.getFormat (internal/modules/esm/loader.js:113:42)
at Loader.getModuleJob (internal/modules/esm/loader.js:243:31)
at async Loader.import (internal/modules/esm/loader.js:177:17) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
I assume node wants to check the file extension to see if its a .cjs
extension and would require to execute it as common js. However IMHO if there is no file extension it should just respect the package.json
in the parent folder and run it as ESM.