Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
flolu opened this issue Nov 30, 2022 · 8 comments
Open

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

flolu opened this issue Nov 30, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@flolu
Copy link

flolu commented Nov 30, 2022

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 [email protected] failed: (Exit 1): lifecycle-hooks.sh failed: error executing command (from target //:.aspect_rules_js/node_modules/[email protected]/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: [email protected] install: `node buildcheck.js > buildcheck.gypi && node-gyp rebuild`
spawn ENOENT
    at ChildProcess.<anonymous> (/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: '[email protected]',
  stage: 'install',
  script: 'node buildcheck.js > buildcheck.gypi && node-gyp rebuild',
  pkgname: 'cpu-features'
}

> [email protected] install /home/flolu/.cache/bazel/_bazel_flolu/8f204a9bf8f980884283ff5b6ddf7d91/execroot/__main__/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/[email protected]/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

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)

@flolu flolu added the bug Something isn't working label Nov 30, 2022
@matthewjh
Copy link

I am seeing this, too, for sse4_crc32. APPDATA=. didn't work for me (not sure whether that was sharp=specific, though).

@flolu
Copy link
Author

flolu commented Dec 8, 2022

@matthewjh Yes I think the APPDATA environment variable is sharp-sepcific

@alexjpwalker
Copy link

Same issue here on MacOS 12.5.1, M1 chip. Failing to install nice-napi.

@alexjpwalker
Copy link

alexjpwalker commented Dec 13, 2022

EDIT: Using lifecycle_hooks_exclude as detailed in linked issues is a far nicer workaround than this one!

It's not ideal, but we've worked around this issue on Mac temporarily by modifying the node-gyp script. The cost is that the user must now install node-gyp globally through npm. https://github.com/vaticle/rules_js/blob/node-gyp-hack/npm/private/lifecycle/min/node-gyp-bin/node-gyp

When node-gyp is not installed globally, it prints a warning which can be safely ignored on Linux.

#!/usr/bin/env sh
node_gyp_script="/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js"
if test -f "$node_gyp_script"; then
  node "$node_gyp_script" "$@"
else
  echo "Could not locate node-gyp. If building on Mac, install it globally by running: npm i -g node-gyp"
  if [ "x$npm_config_node_gyp" = "x" ]; then
    node "`dirname "$0"`/../../node_modules/node-gyp/bin/node-gyp.js" "$@"
  else
    "$npm_config_node_gyp" "$@"
  fi
fi

A similar solution should work for Windows by modifying node-gyp.cmd.

@flolu
Copy link
Author

flolu commented Jan 9, 2023

I fixed this issue by adding the following to the npm_translate_lock inside WORKSPACE:

lifecycle_hooks_exclude = [
    "cpu-features",
],

Thanks to @pcj for pointing this out.

@flolu flolu closed this as completed Jan 9, 2023
@matthewjh
Copy link

Isn't that a workaround, not a fix, @flolu? Why close the issue?

@flolu
Copy link
Author

flolu commented Jan 9, 2023

@matthewjh yes, you are absolutely right!

@flolu flolu reopened this Jan 9, 2023
@gregmagolan gregmagolan moved this to 📋 Backlog in Open Source Feb 4, 2023
@matthewjh
Copy link

My problem was fixed by #954. Thanks @hunshcn!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants