-
Notifications
You must be signed in to change notification settings - Fork 524
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
ESM support #3277
Comments
I order to support |
This issue has been automatically marked as stale because it has not had any activity for 6 months. It will be closed if no further activity occurs in 30 days. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs! |
Any progress on ESM support? Is required in Angular 13 |
This issue has been automatically marked as stale because it has not had any activity for 6 months. It will be closed if no further activity occurs in 30 days. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs! |
This issue was automatically closed because it went 30 days without any activity since it was labeled "Can Close?" |
🚀 feature request
Relevant Rules
ts_project
nodejs_binary
jasmine_node_test
Maybe others, but these are the ones I'm familiar with
Description
Describe alternatives you've considered
I don't believe there's alternate ways to run ESM JS without core support in rules_nodejs
The primary motivation for this feature is for support of Angular v13 which only publishes ESM JS.
The general rule with ESM is that an ESM file can import CJS or ESM, and CJS can require CJS and import ESM only via the
import()
function. Therefore you cannotrequire()
ESM from a CJS file.This means that a codebase which runs a
jasmine_node_test
as it stands is unable to import Angular v13 (or any other ESM only packages)(please correct me if this is wrong)
My understanding of how NodeJS picks what module format to run a file in is determined by:
First it will look at file extention: .cjs -> CJS, .mjs -> ESM
If the extension is .js then it looks at the package.json field "type", where module -> ESM, commonjs -> CJS
See "ESM_FILE_FORMAT" in the NodeJS docs for a detailed algorithm
With the above in mind I think the changes required to support ESM with nodejs_binary would be to rename internal JS files (node_patches.js, jasmine_runner.js) to be *.cjs, with the exception of loader.js which will need to be modified to be able to
import()
the users entry_pointFor
ts_library
I think the most unambiguous method would be to have it output.mjs
files, however that's not currently supported and there's a lot of discussion, see some of the threads around here microsoft/TypeScript#18442Therefore I think the next best option is just to output .js files then the user will need to ensure they have a package.json with type=module in order to declare the output to be ESM, this will need some docs.
That would mean no changes are needed to the rule itself.
NodeJS docs: https://nodejs.org/api/esm.html
The text was updated successfully, but these errors were encountered: