Repository navigation
Closed
Description
Not sure if this is an issue with babel or bazel or a combination, but I am just trying to write a js_library that uses babel to downlevel es6 to amd. I am running into issues with babel trying to load its plugins. I started out just using the cli and passing it a .babelrc - but now also tried using the node api for easier debugging.
So quite simple, for testing now I have:
nodejs_binary(
name = "babel",
entry_point = "__main__/common/bazel/rules/js/babel.js",
data = [
"babel.js",
"@js_library_deps//:node_modules",
],
node_modules = "@js_library_deps//:node_modules",
visibility = ["//visibility:public"],
)
// babel.js
const babel = require("@babel/core");
// This require does work.
// const transform_plugin = require("@babel/plugin-transform-modules-amd");
console.log(babel.transformFileSync("./babel.js", {
plugins: ["@babel/plugin-transform-modules-amd"]
}).code);
Then, when executing this via bazel run I get:
at Function.module.exports [as sync] (/home/markus/.cache/bazel/_bazel_markus/c83dd5dc66625baf386a59b750f50a10/execroot/__main__/bazel-out/k8-fastbuild/bin/common/bazel/rules/js/babel.runfiles/js_library_deps/node_modules/resolve/lib/sync.js:42:15)
at resolveStandardizedName (/home/markus/.cache/bazel/_bazel_markus/c83dd5dc66625baf386a59b750f50a10/execroot/__main__/bazel-out/k8-fastbuild/bin/common/bazel/rules/js/babel.runfiles/js_library_deps/node_modules/@babel/core/lib/config/files/plugins.js:100:31)
at resolvePlugin (/home/markus/.cache/bazel/_bazel_markus/c83dd5dc66625baf386a59b750f50a10/execroot/__main__/bazel-out/k8-fastbuild/bin/common/bazel/rules/js/babel.runfiles/js_library_deps/node_modules/@babel/core/lib/config/files/plugins.js:53:10)
at loadPlugin (/home/markus/.cache/bazel/_bazel_markus/c83dd5dc66625baf386a59b750f50a10/execroot/__main__/bazel-out/k8-fastbuild/bin/common/bazel/rules/js/babel.runfiles/js_library_deps/node_modules/@babel/core/lib/config/files/plugins.js:61:20)
at createDescriptor (/home/markus/.cache/bazel/_bazel_markus/c83dd5dc66625baf386a59b750f50a10/execroot/__main__/bazel-out/k8-fastbuild/bin/common/bazel/rules/js/babel.runfiles/js_library_deps/node_modules/@babel/core/lib/config/config-descriptors.js:135:21)
at items.map (/home/markus/.cache/bazel/_bazel_markus/c83dd5dc66625baf386a59b750f50a10/execroot/__main__/bazel-out/k8-fastbuild/bin/common/bazel/rules/js/babel.runfiles/js_library_deps/node_modules/@babel/core/lib/config/config-descriptors.js:87:50)
at Array.map (<anonymous>)
at createDescriptors (/home/markus/.cache/bazel/_bazel_markus/c83dd5dc66625baf386a59b750f50a10/execroot/__main__/bazel-out/k8-fastbuild/bin/common/bazel/rules/js/babel.runfiles/js_library_deps/node_modules/@babel/core/lib/config/config-descriptors.js:87:29)
at createPluginDescriptors (/home/markus/.cache/bazel/_bazel_markus/c83dd5dc66625baf386a59b750f50a10/execroot/__main__/bazel-out/k8-fastbuild/bin/common/bazel/rules/js/babel.runfiles/js_library_deps/node_modules/@babel/core/lib/config/config-descriptors.js:83:10)
at alias (/home/markus/.cache/bazel/_bazel_markus/c83dd5dc66625baf386a59b750f50a10/execroot/__main__/bazel-out/k8-fastbuild/bin/common/bazel/rules/js/babel.runfiles/js_library_deps/node_modules/@babel/core/lib/config/config-descriptors.js:75:49)
Executing it with node directly works as expected.
Metadata
Metadata
Assignees
Labels
No labels
Activity
alexeagle commentedon May 29, 2018
It seems like something is missing from the pasted error - it's just a stack with no message text?
If the error is in module resolution, I usually make local edits to enable extra debugging - in
node_launcher.shyou can print the filesystem contents in the sandbox where the build is running, and innode_loader.jsyou can add more println debugging to see what is beingrequired - usually it's a trivial matter of some paths being relative to the wrong thing, once you see what node is trying to resolve and what .js files are present for it to read.DM me if you need more help?
Globegitter commentedon Jun 11, 2018
Just posting this here for completeness sake, I did indeed manage to cut some of the output and here is the full output based on what is in the PR:
Looking further into it just now
Edit:
Aahh, I think the source of the issue is babel using https://github.com/browserify/resolve to load the plugins which then I guess does not use the patched require() function.
Globegitter commentedon Jun 12, 2018
The issue was indeed due to the resolve library and we fixed this now in a pairing session with @alexeagle by simply requiring the plugin first in the
babel.rc.js.mattjs commentedon Feb 6, 2019
@Globegitter Any chance you could post some example code of using babel with this issue fixed? Trying to get this working myself!
Globegitter commentedon Apr 3, 2019
@mattmoor sorry just seeing this now, here an example of one of our
babel.config.jsfiles: