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
node --experimental-modules does not allow running files without an extension #16605
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:
Add a --module option to node to "tell" Node that the main module is an es module and not a CJS module.
Any file that is run via cli and does not have an mjs extension is always a CJS module. This will force people in the future to await 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.
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.
Activity
targos commentedon Oct 30, 2017
Related: nodejs/node-eps#62
Trott commentedon Nov 11, 2018
I see this bug in 8.x, but it seems to be fixed in 10.x and 11.x.
devsnek commentedon Nov 11, 2018
definitely safe to close at this point
Grief commentedon Mar 4, 2020
Have the same issue with 13.9 while it was ok in 13.8!
jeffs commentedon May 5, 2020
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.
guybedford commentedon May 5, 2020
@jeffs can you please post a new issue with a replication?
jeffs commentedon May 5, 2020
@guybedford #33259