rules_nodejs icon indicating copy to clipboard operation
rules_nodejs copied to clipboard

ts_library outputs .mjs files with invalid import statements

Open mattsoulanille opened this issue 4 years ago β€’ 2 comments

🐞 bug report

Affected Rule

The issue is caused by the rule: ts_library

Is this a regression?

Unlikely

Description

ts_library outputs the JSEcmaScriptModuleInfo provider, but the files it creates don't completely match the ECMAScript spec. Specifically, import statements do not have file extensions for relative imports. More details in the minimal reproduction.

Perhaps ts_library could rewrite relative imports in .mjs so that they include the .mjs extension. These rewrites would only happen if the imported file was from another JSEcmaScriptModuleInfo provider. This is probably very difficult, though.

πŸ”¬ Minimal Reproduction

https://github.com/mattsoulanille/ts_library_invalid_import

πŸ”₯ Exception or Error

Causes this exception when consuming .mjs outputs in webpack:


BREAKING CHANGE: The request './src/foo' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

🌍 Your Environment

Operating System:

  
MacOS 12.2 arm, but this is not OS-dependent
  

Output of bazel version:

  
Build label: 5.0.0
Build target: bazel-out/darwin_arm64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Jan 19 14:16:16 2022 (1642601776)
Build timestamp: 1642601776
Build timestamp as int: 1642601776
  

Rules_nodejs version:

(Please check that you have matching versions between WORKSPACE file and @bazel/* npm packages.)

  
5.1.0
  

Anything else relevant?

mattsoulanille avatar Feb 08 '22 23:02 mattsoulanille

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!

github-actions[bot] avatar Aug 11 '22 03:08 github-actions[bot]

This issue was automatically closed because it went 30 days without any activity since it was labeled "Can Close?"

github-actions[bot] avatar Sep 10 '22 03:09 github-actions[bot]