-
Notifications
You must be signed in to change notification settings - Fork 477
Override module type for CommonJS runtime #8194
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
base: master
Are you sure you want to change the base?
Conversation
cknitt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Previously, this used to be the other way around. The whole package was common JS, and it was overridden for ES6. That override is still there in https://github.com/rescript-lang/rescript/blob/master/packages/%40rescript/runtime/lib/es6/package.json and could be removed now.
af0581f to
eeda32d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this anymore because the root package.json has type set to module.
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
I wonder why this problem has never surfaced before for v12. It seems we did not have any kind of test for this after moving For the CHANGELOG, could you adapt the wording so that it is clearer what the bug is that is being fixed here? |
|
I am also asking myself if it would be hard to just explicitly use the corresponding file extensions (.mjs, .cjs) instead. (But not in this PR, here we should keep the fix minimal for easy backportiing. We can investigate this later.) |
7322601 to
3988236
Compare
The
@rescript/runtime packagehas"type": "module"in its rootpackage.json, which tells Node.js to treat all.jsfiles as ES modules. However, the files inlib/js/*are actually written in CommonJS format (usingrequire()andexports).When Node.js tries to load these files via
require(), it throws:This breaks any code that runs directly with Node.js (outside of build tools) because the nearest root
package.jsonhas its type set to module.This follows the https://nodejs.org/api/packages.html#dual-commonjses-module-packages. The nested package.json files override the parent's
"type"declaration. This adds explicitpackage.jsonfile with type set to commonjs (similar to what we have inlib/es6/package.jsonbut withmoduleset).