The issue is caused by the rule: npm_install
Not as far as I know
When including the canvas package the install script fails when using node-pre-gyp to download the binary module.
On Windows, the problem seems to be running the script in the first place:
1592 verbose lifecycle [email protected]~install: CWD: C:\Users\geoff\code\rules_nodejs_canvas\node_modules\canvas
1593 silly lifecycle [email protected]~install: Args: [ '/d /s /c', 'node-pre-gyp install --fallback-to-build' ]
1594 silly lifecycle [email protected]~install: Returned: code: 1 signal: null
1595 info lifecycle [email protected]~install: Failed to exec install script
...
1603 verbose stack Error: [email protected] install: `node-pre-gyp install --fallback-to-build`
1603 verbose stack Exit status 1
1603 verbose stack at EventEmitter.<anonymous> (C:\Users\geoff\_bazel_geoff\bpy25k5q\external\nodejs_windows_amd64\bin\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
1603 verbose stack at EventEmitter.emit (events.js:210:5)
1603 verbose stack at ChildProcess.<anonymous> (C:\Users\geoff\_bazel_geoff\bpy25k5q\external\nodejs_windows_amd64\bin\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
1603 verbose stack at ChildProcess.emit (events.js:210:5)
1603 verbose stack at maybeClose (internal/child_process.js:1021:16)
1603 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
On Mac/Linux the error seems to be in the way the node-pre-gyp CLI bin requires "itself" (the package):
> node-pre-gyp install --fallback-to-build
(internal/modules/cjs/loader.js:583)
throw err;
^
Error: Cannot find module '../'
## 馃敩 Minimal Reproduction
https://github.com/gmishkin/rules_nodejs_canvas
## 馃敟 Exception or Error
PS C:\Users\geoff\code\rules_nodejs_canvas> bazel build --define=VERBOSE_LOGS=1 :main
Starting local Bazel server and connecting to it...
INFO: Call stack for the definition of repository 'npm' which is a npm_install (rule definition at C:/users/geoff/_bazel_geoff/bpy25k5q/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl:298:15):
- C:/users/geoff/_bazel_geoff/bpy25k5q/external/build_bazel_rules_nodejs/index.bzl:77:5
- C:/users/geoff/code/rules_nodejs_canvas/WORKSPACE:27:1
ERROR: An error occurred during the fetch of repository 'npm':
npm_install failed:
> [email protected] install C:\Users\geoff\code\rules_nodejs_canvas\node_modules\canvas
> node-pre-gyp install --fallback-to-build
(The system cannot find the path specified.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\geoff\AppData\Roaming\npm-cache\_logs\2019-12-19T22_52_22_402Z-debug.log
)
ERROR: C:/users/geoff/code/rules_nodejs_canvas/BUILD:3:1: //:main depends on @npm//canvas:canvas in repository @npm which failed to fetch. no such package '@npm//canvas': npm_install failed:
> [email protected] install C:\Users\geoff\code\rules_nodejs_canvas\node_modules\canvas
> node-pre-gyp install --fallback-to-build
(The system cannot find the path specified.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\geoff\AppData\Roaming\npm-cache\_logs\2019-12-19T22_52_22_402Z-debug.log
)
ERROR: Analysis of target '//:main' failed; build aborted: no such package '@npm//canvas': npm_install failed:
> [email protected] install C:\Users\geoff\code\rules_nodejs_canvas\node_modules\canvas
> node-pre-gyp install --fallback-to-build
(The system cannot find the path specified.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\geoff\AppData\Roaming\npm-cache\_logs\2019-12-19T22_52_22_402Z-debug.log
)
INFO: Elapsed time: 8.246s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (21 packages loaded, 28 targets configured)
## 馃實 Your Environment
**Operating System:**
Windows 10 Version 1909
macOS Mojave latest
Ubuntu Linux 19.10
Output of bazel version:
Build label: 1.2.1
Build target: bazel-out/x64_windows-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Nov 26 15:24:17 2019 (1574781857)
Build timestamp: 1574781857
Build timestamp as int: 1574781857
Rules_nodejs version:
(Please check that you have matching versions between WORKSPACE file and @bazel/* npm packages.)
0.42.3
Anything else relevant?
running npm ci itself works
Yes, sorry, we still don't hook our install with a working gyp setup for doing C++ compilation. See #506
I think this error is a bit different, this package has a binary module download available for this platform that the install script tries to use, but the install script fails to require its own package (I think) presumably some issue with relative require and the rules鈥檚 require shim.
Something about this line the wrapper鈥檚 require doesn鈥檛 like https://github.com/mapbox/node-pre-gyp/blob/ef634f92f562cde064fbf831896fef045a47f9a1/bin/node-pre-gyp#L15
We're running into this as well. I've been getting around it by running yarn outside of bazel. Not ideal. We did not run into this with rules_nodejs version 0.39.1, but we upgraded to 1.2.0 22 days ago and this has started happening.
We have the same error as @gmishkin, but ours is for grpc
@zaucy I worked around it by setting preserve_symlinks = False in the WORKSPACE but turning it back on in all our nodejs_binary rules.
Reason is with preserve_symlinks on it can't find itself out of node_modules/.bin.
Most helpful comment
@zaucy I worked around it by setting
preserve_symlinks = Falsein the WORKSPACE but turning it back on in all ournodejs_binaryrules.Reason is with preserve_symlinks on it can't find itself out of
node_modules/.bin.