The issue is caused by the rule:
npm_umd_bundle
No
UMD bundling fails for the url npm package.
Side note: I want to use the UMD bundle in a ts_devserver rule, which is a workflow that works fine for other npm packages.
https://github.com/hperl/bazel_rules_node_url_repro/tree/2d0b00d1a5a26c1d87ac95ce426ba175ff3f1df3
bazel build @npm//url:url__umd
## 馃敟 Exception or Error
INFO: Analyzed target @npm//url:url__umd (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /home/perl/.cache/bazel/_bazel_perl/efdc861f1352c352df7284b09f054429/external/npm/url/BUILD.bazel:86:1: Generated UMD bundle for url npm package [browserify] failed (Exit 1) browserify-wrapped failed: error executing command bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/npm_install/browserify-wrapped repro url external/npm/node_modules/url/url.js bazel-out/k8-fastbuild/bin/external/npm/url/url.umd.js
Use --sandbox_debug to see verbose messages from the sandbox
Error: Cannot find module './decode' from '/home/perl/.cache/bazel/_bazel_perl/efdc861f1352c352df7284b09f054429/external/build_bazel_rules_nodejs/third_party/npm/node_modules/browserify'
at /home/perl/.cache/bazel/_bazel_perl/efdc861f1352c352df7284b09f054429/external/build_bazel_rules_nodejs/third_party/npm/node_modules/browserify/index.js:90:41289
at e (/home/perl/.cache/bazel/_bazel_perl/efdc861f1352c352df7284b09f054429/external/build_bazel_rules_nodejs/third_party/npm/node_modules/browserify/index.js:90:41441)
at p (/home/perl/.cache/bazel/_bazel_perl/efdc861f1352c352df7284b09f054429/external/build_bazel_rules_nodejs/third_party/npm/node_modules/browserify/index.js:90:42114)
at /home/perl/.cache/bazel/_bazel_perl/efdc861f1352c352df7284b09f054429/external/build_bazel_rules_nodejs/third_party/npm/node_modules/browserify/index.js:90:40495
at FSReqWrap.oncomplete (fs.js:153:21)
Error: Command failed: node /home/perl/.cache/bazel/_bazel_perl/efdc861f1352c352df7284b09f054429/sandbox/linux-sandbox/2/execroot/repro/bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/npm_install/browserify-wrapped.runfiles/build_bazel_rules_nodejs/third_party/npm/node_modules/browserify/index.js external/npm/node_modules/url/url.js --preserve-symlinks -t [ /home/perl/.cache/bazel/_bazel_perl/efdc861f1352c352df7284b09f054429/sandbox/linux-sandbox/2/execroot/repro/bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/npm_install/browserify-wrapped.runfiles/build_bazel_rules_nodejs/third_party/npm/node_modules/babelify/index.js --plugins [ /home/perl/.cache/bazel/_bazel_perl/efdc861f1352c352df7284b09f054429/sandbox/linux-sandbox/2/execroot/repro/bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/npm_install/browserify-wrapped.runfiles/build_bazel_rules_nodejs/third_party/npm/node_modules/@babel/plugin-transform-modules-commonjs/index.js ] ] -p [ /home/perl/.cache/bazel/_bazel_perl/efdc861f1352c352df7284b09f054429/sandbox/linux-sandbox/2/execroot/repro/bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/npm_install/browserify-wrapped.runfiles/build_bazel_rules_nodejs/third_party/npm/node_modules/named-amd/index.js --name url ] -s browserify_repro_url -o bazel-out/k8-fastbuild/bin/external/npm/url/url.umd.js -u
at checkExecSyncError (child_process.js:629:11)
at Object.execFileSync (child_process.js:647:13)
at runBrowserify (/home/perl/.cache/bazel/_bazel_perl/efdc861f1352c352df7284b09f054429/sandbox/linux-sandbox/2/execroot/repro/bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/npm_install/browserify-wrapped.runfiles/build_bazel_rules_nodejs/internal/npm_install/browserify-wrapped.js:65:17)
at Object. (/home/perl/.cache/bazel/_bazel_perl/efdc861f1352c352df7284b09f054429/sandbox/linux-sandbox/2/execroot/repro/bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/npm_install/browserify-wrapped.runfiles/build_bazel_rules_nodejs/internal/npm_install/browserify-wrapped.js:29:1)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Object. (/home/perl/.cache/bazel/_bazel_perl/efdc861f1352c352df7284b09f054429/sandbox/linux-sandbox/2/execroot/repro/bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/npm_install/browserify-wrapped.runfiles/build_bazel_rules_nodejs/internal/npm_install/browserify-wrapped_bin_loader.js:528:24)
WARNING: Due to a breaking change in rules_nodejs 0.13.0, target @build_bazel_rules_nodejs//internal/npm_install:browserify-wrapped_bin
must now declare either an explicit node_modules attribute, or
list explicit deps[] or data[] fine grained dependencies on npm labels
if it has any node_modules dependencies.
See https://github.com/bazelbuild/rules_nodejs/wiki#migrating-to-rules_nodejs-013
Target @npm//url:url__umd failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.672s, Critical Path: 0.58s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
## 馃實 Your Environment
**Operating System:**
Linux (archlinux)
Output of bazel version:
Build label: 0.29.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Aug 28 14:34:45 2019 (1567002885)
Build timestamp: 1567002885
Build timestamp as int: 1567002885
Rules version (SHA):
da72ea53fa1cb8ab5ef7781ba06b97259b7d579a431ce480476266bc81bdf21d
Anything else relevant?
I have the same problem. Is there any fix for that? I'm using Bazel in version 2.1.0
I'm also encountering the same problem with the fp-ts-routing npm package, which itself seems likely to be triggered by usage of punycode. @agataHappy @hperl have you happened to find a workaround?
When a package causes problems with UMD bundling I do the following (example for swr):
BUILD.bazel:
rollup_deps = [
"@npm//@rollup/plugin-commonjs",
"@npm//@rollup/plugin-json",
"@npm//@rollup/plugin-node-resolve",
"@npm//@rollup/plugin-replace",
"@npm//react",
"@npm//react-dom",
]
rollup_bundle(
name = "swr",
srcs = ["@npm//swr:swr__files"],
args = ["--output.name=UseSWR"],
config_file = ":umd.rollup.config.js",
entry_point = "@npm//:node_modules/swr/esm/index.js",
format = "umd",
visibility = ["//visibility:public"],
deps = rollup_deps,
)
umd.rollup.config.js (tweak to your liking):
import json from "@rollup/plugin-json";
import nodeResolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import commonjs from "@rollup/plugin-commonjs";
import * as react from "react";
import * as reactDom from "react-dom";
import * as reactIs from "react-is";
import * as propTypes from "prop-types";
module.exports = {
output: [
{
format: "umd",
},
],
plugins: [
replace({
"process.env.NODE_ENV": JSON.stringify("production"),
}),
nodeResolve({ browser: true }),
commonjs({
namedExports: {
react: Object.keys(react),
"react-dom": Object.keys(reactDom),
"prop-types": Object.keys(propTypes),
},
}),
json(),
],
};
Then use it in a ts_devserver bootstrap.js:
var require = {
paths: {
swr: "/ui/swr", // <- where the BUILD.bazel with the swr target is
},
};
This issue has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs in two weeks. 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 two weeks without a reply since it was labeled "Can Close?"
Most helpful comment
When a package causes problems with UMD bundling I do the following (example for swr):
BUILD.bazel:
umd.rollup.config.js (tweak to your liking):
Then use it in a ts_devserver bootstrap.js: