rules_nodejs
rules_nodejs copied to clipboard
ESM modules not working with linker
🐞 bug report
Affected Rule
nodejs_binary
Is this a regression?
No.
Description
When using ESM modules, importing a js_library
with a defined package_name
fails.
🔬 Minimal Reproduction
Consider the following files:
a.js:
export const a = "10"
b.js:
import { a } from "@foo/bar/a.js"
console.log(a)
package.json:
{
"type": "module"
}
BUILD.bazel:
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "nodejs_binary")
js_library(
name = "a",
package_name = "@foo/bar",
srcs = [
"a.js",
"package.json",
],
)
js_library(
name = "b",
srcs = [
"b.js",
"package.json",
],
deps = ["a"],
)
nodejs_binary(
name = "repro",
data = [
"b",
],
entry_point = "b.js",
)
Note that commenting out the package_name
and attribute and importing a.js
by relative path works perfectly.
🔥 Exception or Error
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@foo/bar'
🌍 Your Environment
Operating System:
macOS
Output of bazel version
:
5.1.0
Rules_nodejs version:
(Please check that you have matching versions between WORKSPACE file and @bazel/*
npm packages.)
5.4.0
Anything else relevant?
Seems like this is working in 5.4.1! :)
Spoke too soon, on linux I still hit this.
I can work around this by specifying --node_options=--preserve-symlinks-main
. I wonder if this should be done by default?
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?"