Skip to content

Build Error on Windows while executing the lifecycle hooks #432

Open
@lukasoyen

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

if [ ! -x "$JS_BINARY__NODE_WRAPPER" ]; then
logf_fatal "node wrapper '%s' is not executable" "$JS_BINARY__NODE_WRAPPER"
exit 1
fi
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.<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: '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

binBash = `#!/usr/bin/env bash\nexec node "${path.join(
...segmentsUp,
packageName,
binPath
)}" "$@"`
binEntryPath = path.join(nodeModulesPath, '.bin', binName)
await fs.promises.writeFile(binEntryPath, binBash)
await fs.promises.chmod(binEntryPath, '755') // executable
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" %*
)

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwindowsSpecific to Windows

    Type

    No type

    Projects

    • Status

      📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions