Skip to content
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

[Bug]: error from aspect_rules_js/js/private/node-patches/register.js with type=module in package.json #1756

Closed
matthewjh opened this issue May 24, 2024 · 0 comments · Fixed by #1818
Assignees
Labels
bug Something isn't working

Comments

@matthewjh
Copy link

matthewjh commented May 24, 2024

What happened?

When using a package.json file within packages with "type":"module", a js_binary will error on startup:

[Error [ERR_REQUIRE_ESM]: require() of ES Module /execroot/web/bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/tools/tw-k8s-deployment-pipeline/bin-packaged__js_binary.sh.runfiles/aspect_rules_js/js/private/node-patches/register.js not supported.
register.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename register.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /execroot/web/bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/tools/tw-k8s-deployment-pipeline/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

Fix is probably to use the .cjs extension for register.js

Version

Development (host) and target OS/architectures:

Output of bazel --version:

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

Language(s) and/or frameworks involved:

How to reproduce

No response

Any other information?

No response

@matthewjh matthewjh added the bug Something isn't working label May 24, 2024
@github-actions github-actions bot added the untriaged Requires traige label May 24, 2024
jbedard added a commit to jbedard/rules_js that referenced this issue Jun 26, 2024
@jbedard jbedard removed the untriaged Requires traige label Jun 26, 2024
@jbedard jbedard self-assigned this Jun 26, 2024
jbedard added a commit to jbedard/rules_js that referenced this issue Jun 26, 2024
jbedard added a commit to jbedard/rules_js that referenced this issue Jun 26, 2024
jbedard added a commit to jbedard/rules_js that referenced this issue Jun 26, 2024
jbedard added a commit to jbedard/rules_js that referenced this issue Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants