在Bazel沙箱中运行Remix构建时遇到问题求助
使用Bazel构建Remix应用的问题排查
尝试用Bazel作为Remix应用的构建工具时,开发模式可正常运行,但生产构建失败。以下是遇到的错误及已完成的修复步骤:
1. browserify-zlib@0.1.4的package.json存在重复main字段
- 问题:@remix-run/dev的间接依赖
browserify-zlib@0.1.4的package.json中包含重复的"main"键,导致Bazel无法拉取该仓库 - 修复:将依赖版本替换为
browserify-zlib@0.2.0后解决此问题 - 错误日志:
ERROR: /Users/emmanuel/projects/bbbazel/WORKSPACE:89:17: fetching _npm_import rule //external:npm__browserify-zlib__0.1.4: Traceback (most recent call last): File "/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/external/aspect_rules_js/npm/private/npm_import.bzl", line 471, column 27, in _impl pkg_json = json.decode(rctx.read(pkg_json_path)) Error in decode: at offset 685, object has duplicate key: "main" ERROR: /private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/external/npm/BUILD.bazel:3012:6: @npm//:npm__browserify-zlib__0.1.4_source_directory depends on @npm__browserify-zlib__0.1.4//:source_directory in repository @npm__browserify-zlib__0.1.4 which failed to fetch. no such package '@npm__browserify-zlib__0.1.4//': at offset 685, object has duplicate key: "main"
2. deasync@0.1.28的install钩子调用沙箱中不存在的node-gyp
- 问题:@remix-run/dev的间接依赖
deasync@0.1.28的install生命周期钩子调用了Bazel沙箱内未安装的node-gyp,导致构建失败 - 修复:禁用该包的install钩子后解决此错误,但引发了后续的最终构建问题
- 错误日志:
/Users/emmanuel/projects/bbbazel/BUILD.bazel:5:22: Running lifecycle hooks on npm package deasync@0.1.28 failed: (Exit 1): lifecycle-hooks.sh failed: error executing command (from target //:.aspect_rules_js/node_modules/deasync@0.1.28/lc) bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/aspect_rules_js/npm/private/lifecycle/lifecycle-hooks.sh deasync ../../../external/npm__deasync__0.1.28/package ... (remaining 1 argument skipped) /private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/external/aspect_rules_js/npm/private/lifecycle/min/node-gyp-bin/node-gyp: line 5: 1211: command not found node-gyp not found! Please upgrade your install of npm! You need at least 1.1.5 (I think) and preferably 1.1.30. > deasync@0.1.28 install /private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/deasync@0.1.28/node_modules/deasync > node ./build.js =============================================================== Failure while running lifecycle hook for package 'deasync@0.1.28': Script: 'install' Command: `node ./build.js` Stack trace: spawn ENOENT at ChildProcess.<anonymous> (/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/external/aspect_rules_js/npm/private/lifecycle/min/index.min.js:1:91930) at ChildProcess.emit (node:events:513:28) at maybeClose (node:internal/child_process:1100:16) at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)
3. Remix提示构建入口点输出缺失
- 问题:Remix构建时报错提示"Missing output for entry point",错误信息标注为Remix Bug,但该问题仅在Bazel沙箱环境中出现,推测是Bazel与Remix的交互问题
- 当前状态:未解决
- 错误日志:
The following error is a bug in Remix; please open an issue! https://github.com/remix-run/remix/issues/new Missing output for entry point Error at Object.onCompileFailure (/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/sandbox/darwin-sandbox/1566/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@remix-run+dev@1.12.0_@remix-run+serve@1.12.0/node_modules/@remix-run/dev/dist/cli/commands.js:180:13) at Object.compile (/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/sandbox/darwin-sandbox/1566/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@remix-run+dev@1.12.0_@remix-run+serve@1.12.0/node_modules/@remix-run/dev/dist/compiler/remixCompiler.js:34:134) at async Object.build (/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/sandbox/darwin-sandbox/1566/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@remix-run+dev@1.12.0_@remix-run+serve@1.12.0/node_modules/@remix-run/dev/dist/compiler/build.js:33:3) at async Object.build (/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/sandbox/darwin-sandbox/1566/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@remix-run+dev@1.12.0_@remix-run+serve@1.12.0/node_modules/@remix-run/dev/dist/cli/commands.js:175:3) at async Object.run (/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/sandbox/darwin-sandbox/1566/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@remix-run+dev@1.12.0_@remix-run+serve@1.12.0/node_modules/@remix-run/dev/dist/cli/run.js:449:7) Building Remix app in production mode... Target //examples/remix:build failed to build
额外测试情况
在Bazel沙箱外,使用pnpm添加browserify-zlib@0.2.0覆盖依赖,并通过pnpm install --ignore-scripts安装后,Remix应用可正常完成构建。目前不确定问题根源在Remix还是Bazel,寻求相关经验或可行解决方案。
内容的提问来源于stack exchange,提问作者Neelima
相关产品推荐
相关产品推荐

