-
Notifications
You must be signed in to change notification settings - Fork 504
Add mjs support #800
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
Add mjs support #800
Conversation
|
And now there is a reason this should go into 4.0: requiring an MJS file requires Node 20 or later in order to function. |
|
@jdmarshall could you please update the wiki?
|
|
i have updated it 4.0.0 but still throwing this error throw new Error("Cannot parse config file: '" + fullFilename + "': " + e3); |
|
@nikhilmisra63 You have to have a new enough Node version. Check that your Node version supports .mjs files. Also, that error could be thrown because your config file can't be parsed because the syntax in the file is wrong. You haven't provided enough information to be certain what the problem is. Can you run |
|
@markstos yes i'm on node 22.11 also all of my files in mjs it just the config module is not working. even i tried to create a sample project where i have just created a default.mjs file inside config folder then a index.mjs with two lines of code |
|
What’s the original error? Breakpoint on that line and paste the entire stack trace here. |
|
@jdmarshall @markstos and this is what i'm getting /Users/nikhil/Sourcecode/node/dadahub/test/node_modules/config/lib/config.js:862 Error: Cannot parse config file: '/Users/nikhil/Sourcecode/node/dadahub/test/config/default.mjs': Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/nikhil/Sourcecode/node/dadahub/test/config/default.mjs not supported. Node.js v22.11.0 |
|
You've got something else going on and rather than play twenty questions it'd be good if you started with a single, empty mjs file and built up one set of data at a time until you can narrow down the problem with it. I'm seeing no issues with a simple default.mjs file when I import or require config$4.0.0 |
|
not sure what is real issue but i'm trying to run the same code which i have attached in my last comment and that has only one file and still i'm getting the error. for now i move to .json instead of .mjs and it is working fine. |
|
I tried your sample file. Unable to reproduce.
how are you starting? You're leaving out bits of your repro case and I haven't left out any of mine. |
|
nodejs/node#56927 I think your node versions may be too old. |
|
Hey, just found the culprit — it wasn’t working with Node 22.11, but after updating to 22.14, it’s working fine. I should’ve tested with other versions earlier. Really appreciate your efforts on this, @jdmarshall — thanks a lot! |
|
Okay. Looks like I need to update the docs and release notes. I misremembered these as being a launch feature and it seems that’s only in 24. |
|
Done |

If we are talking about 4.0 happening soon I think it would be good for this change from #786 to land in it - adding MJS support.
Tricky thing is though that
require()on mjs files didn't get backward compatibility until Node 20, and that's a fairly big jump from where we were before.