aspect-build / aspect-build/rules_js

Build Error on Windows while executing the lifecycle hooks

Open
#432 5 comments 0 reactions 0 assignees View on GitHub
bug help wanted windows
Dominant language
Starlark
Stars
378
Forks
183
Avg merge
1d 9h
Merged PRs (30d)
32

Description

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 source-map@0.6.1 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/source-map@0.6.1/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/source-map@0.6.1/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 sharp@0.30.7 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/sharp@0.30.7/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/sharp@0.30.7/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\sharp@0.30.7\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: sharp@0.30.7 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. (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. (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: 'sharp@0.30.7',
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'
}

> sharp@0.30.7 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\sharp@0.30.7\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:

```bat
@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" %*
)
```

Contributor guide

Open the contributing guide

Research direction

Start with js/private/js_binary.sh.tpl lines 304-307 and npm/private/lifecycle/lifecycle-hooks.js lines 49-56, then compare the generated lifecycle and .bin wrappers with the Windows batch file produced by yarn install. Done means the executable check works for symlinked .bat files and lifecycle hooks can resolve commands such as prebuild-install on Windows; verify with the reported source-map and sharp cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
build-system, devtools, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.