aspect-build / aspect-build/rules_js

[Bug]: node-gyp: command not found (When installing testcontainers)

Open
#669 9 comments 2 reactions 0 assignees View on GitHub
bug can close?
Dominant language
Starlark
Stars
378
Forks
183
Avg merge
1d 11h
Merged PRs (30d)
29

Description

### What happened?

Repro: https://github.com/flolu/rules-js-node-gyp-error

Building this `ts_project` fails after adding the `//:node_modules/testcontainers` dependency.

```
ts_project(
name = "app",
srcs = ["main.ts"],
declaration = True,
transpiler = partial.make(
swc,
swcrc = "//:swcrc",
),
tsconfig = "//:tsconfig",
deps = [
"//:node_modules/@types/node",
"//:node_modules/testcontainers",
],
)
```

The error is:
```
ERROR: /home/flolu/Desktop/rules-js-node-gyp-error/BUILD.bazel:18:22: Running lifecycle hooks on npm package cpu-features@0.0.4 failed: (Exit 1): lifecycle-hooks.sh failed: error executing command (from target //:.aspect_rules_js/node_modules/cpu-features@0.0.4/lc) bazel-out/k8-opt-exec-2B5CBBC6/bin/external/aspect_rules_js/npm/private/lifecycle/lifecycle-hooks.sh cpu-features ../../../external/npm__cpu-features__0.0.4/package ... (remaining 1 argument skipped)
/home/flolu/.cache/bazel/_bazel_flolu/8f204a9bf8f980884283ff5b6ddf7d91/execroot/__main__/bazel-out/k8-fastbuild/bin/external/aspect_rules_js/npm/private/lifecycle/min/node-gyp-bin/node-gyp: line 5: 1010: command not found
Error: cpu-features@0.0.4 install: `node buildcheck.js > buildcheck.gypi && node-gyp rebuild`
spawn ENOENT
at ChildProcess. (/home/flolu/.cache/bazel/_bazel_flolu/8f204a9bf8f980884283ff5b6ddf7d91/execroot/__main__/bazel-out/k8-fastbuild/bin/external/aspect_rules_js/npm/private/lifecycle/min/index.min.js:1:79716)
at ChildProcess.emit (node:events:394:28)
at maybeClose (node:internal/child_process:1064:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5) {
code: 'ELIFECYCLE',
errno: 'ENOENT',
syscall: 'spawn',
file: 'sh',
pkgid: 'cpu-features@0.0.4',
stage: 'install',
script: 'node buildcheck.js > buildcheck.gypi && node-gyp rebuild',
pkgname: 'cpu-features'
}

> cpu-features@0.0.4 install /home/flolu/.cache/bazel/_bazel_flolu/8f204a9bf8f980884283ff5b6ddf7d91/execroot/__main__/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/cpu-features@0.0.4/node_modules/cpu-features
> node buildcheck.js > buildcheck.gypi && node-gyp rebuild
```

### Version

Development (host) and target OS/architectures: Linux (Fedora)

Output of `bazel --version`:
```
Bazelisk version: v1.13.2
Build label: 7.0.0-pre.20221102.3
```

Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file:
- rules_js-1.8.0
- rules_ts-1.0.2
- rules_swc-0.19.3

Language(s) and/or frameworks involved:

### How to reproduce

```shell
git clone https://github.com/flolu/rules-js-node-gyp-error
cd rules-js-node-gyp-error
pnpm i
bazel run //:bin
```

### Any other information?

A similar error occurs with the `sharp` package. This can be fixed by setting `APPDATA=.` in `lifecycle_hooks_envs` of `npm_translate_lock`. (See #217)

Contributor guide

Open the contributing guide

Research direction

Start with the linked rules-js-node-gyp-error reproduction and run pnpm i followed by bazel run //:bin. Inspect BUILD.bazel and the npm_translate_lock lifecycle_hooks_envs configuration, comparing the related guidance in #217. Done means the reproduction builds without the node-gyp command-not-found failure when testcontainers pulls in cpu-features.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.