-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
node --experimental-modules does not allow running files without an extension #16605
Comments
Related: nodejs/node-eps#62 |
I see this bug in 8.x, but it seems to be fixed in 10.x and 11.x. |
definitely safe to close at this point |
Have the same issue with 13.9 while it was ok in 13.8! |
I'm having this problem with v14.2.0, even without passing --experimental-modules (which is on by default in v14), even though node v12 works fine. This is a severe regression. Please re-open. |
@jeffs can you please post a new issue with a replication? |
Assuming the file
./node_modules/.bin/mocha
exists (without a file extension!), this will work:But this won't:
It fails with
ERR_UNKNOWN_FILE_EXTENSION
. Which makes sense, given that it doesn't know whether it's a cjs or esm file.But unfortunately, once
--experimental-modules
is not an experiment anymore, this will be a regression bug, and all cases where files without extensions are run will fail. This is unfortunate, because a lot of people (including me!) use this "trick" of not having an extension to make it a Unix executable by adding a hash bang at the beginning, e.g.:#!/usr/bin/env node
.Not sure how to resolve this, but I'm assuming that for reasons of backward compatibility, once we are out of the experiment, then this MUST work and resolve to CJS. I see two options going forward:
--module
option to node to "tell" Node that the main module is an es module and not a CJS module.mjs
extension is always a CJS module. This will force people in the future toawait import
the "real" module.While I prefer option #1 when the ESM dust settles in a few years, for the present I would prefer option #2 given that its an exception to the rule "MJS" if and only if "ESM", and because the rules surrounding ESM are not yet intuitive to everybody.
This bug is somewhat a companion bug to #16476.
The text was updated successfully, but these errors were encountered: