rules_js
rules_js copied to clipboard
Build Error on Windows while executing the lifecycle hooks
I get the following build error on Windows with rules_js
from the current main
branch while trying to run the lifecycle hooks during the install of an npm package:
ERROR: C:/users/XXX/desktop/XXX/projects/support/icon-converter/BUILD.bazel:5:22: Running lifecycle hooks on npm package [email protected] failed: (Exit 1): lifecycle-hooks.bat failed: error executing command
cd /d C:/users/XXX/XXX/hlezeung/execroot/XXX
SET BAZEL_BINDIR=bazel-out/x64_windows-opt-exec-5360F8F5/bin
SET BAZEL_BUILD_FILE_PATH=projects/support/icon-converter/BUILD.bazel
SET BAZEL_COMPILATION_MODE=opt
SET BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
SET BAZEL_TARGET=@//projects/support/icon-converter:.aspect_rules_js/node_modules/[email protected]/lc
SET BAZEL_TARGET_CPU=x64_windows
SET BAZEL_WORKSPACE=XXX
SET JS_BINARY__PATCH_NODE_FS=1
SET JS_BINARY__SILENT_ON_SUCCESS=1
SET PATH=C:\Users\XXX\Desktop\msys64\usr\bin;C:\Users\XXX\Desktop\msys64\bin;C:\Windows;C:\Windows\System32;C:\Windows\System32\WindowsPowerShell\v1.0
bazel-out\x64_windows-opt-exec-5360F8F5\bin\external\aspect_rules_js\npm\private\lifecycle\lifecycle-hooks.bat source-map ../../../external/npm_icon_converter__source-map__0.6.1/package ../../../bazel-out/x64_windows-opt-exec-5360F8F5/bin/projects/support/icon-converter/node_modules/.aspect_rules_js/[email protected]/node_modules/source-map
# Configuration: d410446df3eee997447691af75b875ddbccaf89aa83d0dacd83fa329eb9845b4
# Execution platform: //projects/support/bazel/platform:windows_x64
FATAL: aspect_rules_js[js_binary]: node wrapper '/c/Users/XXX/XXX/hlezeung/execroot/XXX/bazel-out/x64_windows-opt-exec-5360F8F5/bin/external/aspect_rules_js/npm/private/lifecycle/lifecycle-hooks.bat.runfiles/XXX/../aspect_rules_js/npm/private/lifecycle/lifecycle-hooks_node_wrapper/node.bat' is not executable
This is due to the executable check in https://github.com/aspect-build/rules_js/blob/95f3b545b1f5c017b19d4cfe50cecd3f31a60761/js/private/js_binary.sh.tpl#L304-L307 not working correctly on Windows with a symlink to a bat file.
If this check is removed, the following build error while running the lifecycle hooks during the install of https://www.npmjs.com/package/sharp appears:
'prebuild-install' is not recognized as an internal or external command, operable program or batch file.
Full error:
ERROR: C:/users/XXX/desktop/XXX/projects/support/icon-converter/BUILD.bazel:5:22: Running lifecycle hooks on npm package [email protected] failed: (Exit 1): lifecycle-hooks.bat failed: error executing command
cd /d C:/users/XXX/XXX/hlezeung/execroot/XXX
SET APPDATA=.
SET BAZEL_BINDIR=bazel-out/x64_windows-opt-exec-5360F8F5/bin
SET BAZEL_BUILD_FILE_PATH=projects/support/icon-converter/BUILD.bazel
SET BAZEL_COMPILATION_MODE=opt
SET BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
SET BAZEL_TARGET=@//projects/support/icon-converter:.aspect_rules_js/node_modules/[email protected]/lc
SET BAZEL_TARGET_CPU=x64_windows
SET BAZEL_WORKSPACE=XXX
SET JS_BINARY__PATCH_NODE_FS=1
SET JS_BINARY__SILENT_ON_SUCCESS=1
SET PATH=C:\Users\XXX\Desktop\msys64\usr\bin;C:\Users\XXX\Desktop\msys64\bin;C:\Windows;C:\Windows\System32;C:\Windows\System32\WindowsPowerShell\v1.0
SET npm_config_sharp_libvips_binary_host=https://XXX/github-releases-mirror/lovell/sharp-libvips/releases/download
bazel-out\x64_windows-opt-exec-5360F8F5\bin\external\aspect_rules_js\npm\private\lifecycle\lifecycle-hooks.bat sharp ../../../external/npm_icon_converter__sharp__0.30.7/package ../../../bazel-out/x64_windows-opt-exec-5360F8F5/bin/projects/support/icon-converter/node_modules/.aspect_rules_js/[email protected]/node_modules/sharp
# Configuration: d410446df3eee997447691af75b875ddbccaf89aa83d0dacd83fa329eb9845b4
# Execution platform: //projects/support/bazel/platform:windows_x64
'prebuild-install' is not recognized as an internal or external command,
operable program or batch file.
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'C:\users\XXX\XXX\hlezeung\execroot\XXX\bazel-out\x64_windows-opt-exec-5360F8F5\bin\projects\support\icon-converter\node_modules\.aspect_rules_js\[email protected]\node_modules\sharp\1211'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Error: [email protected] install: `(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)`
Exit status 1
at EventEmitter.<anonymous> (C:\Users\XXX\XXX\hlezeung\execroot\XXX\bazel-out\x64_windows-opt-exec-5360F8F5\bin\external\aspect_rules_js\npm\private\lifecycle\lifecycle-hooks.bat.runfiles\aspect_rules_js\npm\private\lifecycle\min\index.min.js:1:73343)
at EventEmitter.emit (node:events:527:28)
at ChildProcess.<anonymous> (C:\Users\XXX\XXX\hlezeung\execroot\XXX\bazel-out\x64_windows-opt-exec-5360F8F5\bin\external\aspect_rules_js\npm\private\lifecycle\lifecycle-hooks.bat.runfiles\aspect_rules_js\npm\private\lifecycle\min\index.min.js:1:79805)
at ChildProcess.emit (node:events:527:28)
at maybeClose (node:internal/child_process:1092:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5) {
errno: 1,
code: 'ELIFECYCLE',
pkgid: '[email protected]',
stage: 'install',
script: '(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)',
pkgname: 'sharp'
}
> [email protected] install C:\users\XXX\XXX\hlezeung\execroot\XXX\bazel-out\x64_windows-opt-exec-5360F8F5\bin\projects\support\icon-converter\node_modules\.aspect_rules_js\[email protected]\node_modules\sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
This is due to the code in https://github.com/aspect-build/rules_js/blob/95f3b545b1f5c017b19d4cfe50cecd3f31a60761/npm/private/lifecycle/lifecycle-hooks.js#L49-L56 not producing a *.bat
file. A yarn install
on Windows creates the following *.bat
file in the .bin
directory:
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\prebuild-install\bin.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\prebuild-install\bin.js" %*
)
Thanks for the report and the diagnoses. I'll put this on list for the 1.2 release but I don't have a timeline on when it will be fixed. We're always looking for OSS sponsorship to help prioritize issues like this. https://opencollective.com/aspect-build
@lummax There have been quite a few changes to the lifecycle hooks code since this was reported. Is this still an issue for you?
Windows support is low priority for rules_js at this point since the number of users using Windows with rules_js that we know of is quite low and the time that we have to spend on unfunded OSS is limited.
Yes, unfortunately our code still does not work on Windows even with the 1.17.1
of rules_js
. The current error:
ERROR: C:/users/XXX/desktop/XXX/projects/support/icon-converter/BUILD.bazel:5:22: Running lifecycle hooks on npm package [email protected] failed: (Exit 1): lifecycle-hooks.bat failed: error executing command bazel-out\x64_windows-opt\bin\external\aspect_rules_js\npm\private\lifecycle\lifecycle-hooks.bat source-map ../../../external/npm_icon_converter__source-map__0.6.1/package ... (remaining 1 argument skipped)
'""' is not recognized as an internal or external command,
operable program or batch file.
Target //:install failed to build
So the error changed a little, but I think I remember a similar error while tinkering with the rules_js
when I initially opened this ticket.
The sad news: I was unfortunately unable to get buy-in for contributing funding to rules_js
. bazel
migration of our JS/TS was pushed down on the roadmap. And I am leaving this job soon, so I will be unable to access the problematic code and answer questions here. So feel free to close/de prioritize this ticket :/
I'll leave it open for visibility although we have no plans to address complex and expensive rules_js Windows issues at the moment since we don't use Windows ourselves for development and we have no active clients that require it. There is a chance of a client that is using Windows wanting help with rules_js in Q2 or Q3 so we may pick some of the issues up at that point if it materializes.
ERROR: C:/users/XXX/desktop/XXX/projects/support/icon-converter/BUILD.bazel:5:22: Running lifecycle hooks on npm package [email protected] failed: (Exit 1): lifecycle-hooks.bat failed: error executing command bazel-out\x64_windows-opt\bin\external\aspect_rules_js\npm\private\lifecycle\lifecycle-hooks.bat source-map ../../../external/npm_icon_converter__source-map__0.6.1/package ... (remaining 1 argument skipped) '""' is not recognized as an internal or external command, operable program or batch file. Target //:install failed to build
We ran into the same issue. Ultimately, I found that the issue is caused when bash.exe
is not in $PATH
, because of this code.
Adding the correct MSYS2 path (in our case c:\tools\msys64\usr\bin
) to the Windows PATH
variable fixed this error.