运行 npm install 时出现 kexec 错误

Getting kexec error when running npm install

我开始使用 node v12.22.7npm 6.14.15 时出现以下错误(也尝试使用 node v16.13.1npm v8.1.2

> node-gyp rebuild

  CXX(target) Release/obj.target/kexec/src/kexec.o
../src/kexec.cc:19:11: error: no member named 'Handle' in namespace 'v8'
using v8::Handle;
      ~~~~^
../src/kexec.cc:68:27: error: no matching constructor for initialization of 'String::Utf8Value'
        String::Utf8Value str(info[0]);
                          ^   ~~~~~~~
/Users/username/Library/Caches/node-gyp/12.22.7/include/node/v8.h:3142:5: note: candidate constructor not viable: no known conversion from 'v8::Local<v8::Value>' to 'const v8::String::Utf8Value' for 1st argument
    Utf8Value(const Utf8Value&) = delete;
    ^
/Users/username/Library/Caches/node-gyp/12.22.7/include/node/v8.h:3135:5: note: candidate constructor not viable: requires 2 arguments, but 1 was provided
    Utf8Value(Isolate* isolate, Local<v8::Value> obj);
    ^
../src/kexec.cc:78:27: error: no matching constructor for initialization of 'String::Utf8Value'
        String::Utf8Value str(info[0]);
                          ^   ~~~~~~~
/Users/username/Library/Caches/node-gyp/12.22.7/include/node/v8.h:3142:5: note: candidate constructor not viable: no known conversion from 'v8::Local<v8::Value>' to 'const v8::String::Utf8Value' for 1st argument
    Utf8Value(const Utf8Value&) = delete;
    ^
/Users/username/Library/Caches/node-gyp/12.22.7/include/node/v8.h:3135:5: note: candidate constructor not viable: requires 2 arguments, but 1 was provided
    Utf8Value(Isolate* isolate, Local<v8::Value> obj);
    ^
../src/kexec.cc:91:75: error: no matching member function for call to 'ToString'
            String::Utf8Value arg(argv_handle->Get(Nan::New<Integer>(i))->ToString());
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/Users/username/Library/Caches/node-gyp/12.22.7/include/node/v8.h:2668:44: note: candidate function not viable: requires single argument 'context', but no arguments were provided
  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString(
                                           ^
/Users/username/Library/Caches/node-gyp/12.22.7/include/node/v8.h:2684:31: note: candidate function not viable: requires single argument 'isolate', but no arguments were provided
                Local<String> ToString(Isolate* isolate) const);
                              ^
../src/kexec.cc:91:48: warning: 'Get' is deprecated: Use maybe version [-Wdeprecated-declarations]
            String::Utf8Value arg(argv_handle->Get(Nan::New<Integer>(i))->ToString());
                                               ^
/Users/username/Library/Caches/node-gyp/12.22.7/include/node/v8.h:3553:3: note: 'Get' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", Local<Value> Get(Local<Value> key));
  ^
/Users/username/Library/Caches/node-gyp/12.22.7/include/node/v8config.h:328:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/kexec.cc:115:12: error: no template named 'Handle'
void init (Handle<Object> exports) {
           ^
../src/kexec.cc:116:5: error: too few arguments to function call, single argument 'context' was not specified
    EXPORT("kexec", kexec);
    ^~~~~~~~~~~~~~~~~~~~~~
../src/kexec.cc:112:51: note: expanded from macro 'EXPORT'
  Nan::New<FunctionTemplate>(symbol)->GetFunction() \
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/username/Library/Caches/node-gyp/12.22.7/include/node/v8.h:6126:46: note: 'GetFunction' declared here
  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
                                             ^
1 warning and 6 errors generated.
make: *** [Release/obj.target/kexec/src/kexec.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/username/.nvm/versions/node/v12.22.7/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Darwin 20.6.0
gyp ERR! command "/Users/username/.nvm/versions/node/v12.22.7/bin/node" "/Users/username/.nvm/versions/node/v12.22.7/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/username/Documents/Workspace/Code/projectname/node_modules/kexec
gyp ERR! node -v v12.22.7
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN inquirer-autocomplete-prompt-ipt@2.0.0 requires a peer of inquirer@>=7 but none is installed. You must install peer dependencies yourself.
npm WARN inquirer-ordinal-prompt@1.0.0 requires a peer of inquirer@>= 7 but none is installed. You must install peer dependencies yourself.
npm WARN stylelint-config-recommended@1.0.0 requires a peer of stylelint@^8.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN stylelint-config-standard@17.0.0 requires a peer of stylelint@^8.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN zipkin-instrumentation-express@0.16.2 requires a peer of @types/express@^4.0.39 but none is installed. You must install peer dependencies yourself.
npm WARN projectname@0.0.245 No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! kexec@3.0.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the kexec@3.0.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

然后我发现了这个post 恰好没有对 node 7 及以上版本的支持。 所以我降级到 node v6.17.1npm v5.10.0 并得到这个错误:

> kexec@3.0.0 install /Users/username/Documents/Workspace/Code/projectname/node_modules/kexec
> node-gyp rebuild

  CXX(target) Release/obj.target/kexec/src/kexec.o
clang: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
../src/kexec.cc:1:10: fatal error: 'cstdio' file not found
#include <cstdio>
         ^~~~~~~~
1 error generated.
make: *** [Release/obj.target/kexec/src/kexec.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/username/.nvm/versions/node/v6.17.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:219:12)
gyp ERR! System Darwin 20.6.0
gyp ERR! command "/Users/username/.nvm/versions/node/v6.17.1/bin/node" "/Users/username/.nvm/versions/node/v6.17.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/username/Documents/Workspace/Code/projectname/node_modules/kexec
gyp ERR! node -v v6.17.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN inquirer-autocomplete-prompt-ipt@2.0.0 requires a peer of inquirer@>=7 but none is installed. You must install peer dependencies yourself.
npm WARN inquirer-ordinal-prompt@1.0.0 requires a peer of inquirer@>= 7 but none is installed. You must install peer dependencies yourself.
npm WARN stylelint-config-recommended@1.0.0 requires a peer of stylelint@^8.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN stylelint-config-standard@17.0.0 requires a peer of stylelint@^8.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN zipkin-instrumentation-express@0.16.2 requires a peer of @types/express@^4.0.39 but none is installed. You must install peer dependencies yourself.
npm WARN projectname@0.0.245 No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! kexec@3.0.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the kexec@3.0.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

然后我检查这个 post,它提到安装 Command Lines Tools 因为我在 Mac。 虽然它已经安装了,但我用 XCode Version 13.1 (13A1030d) 然后 运行 xcode-select --install

卸载并重新安装了它

我尝试的其他事情是:运行 npm cache clean --force,删除 node-modulespackage-lock.json

参考我组织的 Jenkins 管道后,我发现使用了节点 10。

安装 node v10.24.1npm v6.14.12 解决了问题,但出现以下 kexec 警告。

> kexec@3.0.0 install /Users/username/Documents/Workspace/Code/projectname/node_modules/kexec
> node-gyp rebuild

  CXX(target) Release/obj.target/kexec/src/kexec.o
../src/kexec.cc:68:27: warning: 'Utf8Value' is deprecated [-Wdeprecated-declarations]
        String::Utf8Value str(info[0]);
                          ^
/Users/username/Library/Caches/node-gyp/10.24.1/include/node/v8.h:2891:5: note: 'Utf8Value' has been explicitly marked deprecated here
    V8_DEPRECATED("Use Isolate version",
    ^
/Users/username/Library/Caches/node-gyp/10.24.1/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated))
                            ^
../src/kexec.cc:78:27: warning: 'Utf8Value' is deprecated [-Wdeprecated-declarations]
        String::Utf8Value str(info[0]);
                          ^
/Users/username/Library/Caches/node-gyp/10.24.1/include/node/v8.h:2891:5: note: 'Utf8Value' has been explicitly marked deprecated here
    V8_DEPRECATED("Use Isolate version",
    ^
/Users/username/Library/Caches/node-gyp/10.24.1/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated))
                            ^
../src/kexec.cc:91:31: warning: 'Utf8Value' is deprecated [-Wdeprecated-declarations]
            String::Utf8Value arg(argv_handle->Get(Nan::New<Integer>(i))->ToString());
                              ^
/Users/username/Library/Caches/node-gyp/10.24.1/include/node/v8.h:2891:5: note: 'Utf8Value' has been explicitly marked deprecated here
    V8_DEPRECATED("Use Isolate version",
    ^
/Users/username/Library/Caches/node-gyp/10.24.1/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated))
                            ^
3 warnings generated.
  SOLINK_MODULE(target) Release/kexec.node
npm notice created a lockfile as package-lock.json. You should commit this file.

added 1 package from 1 contributor and audited 1286 packages in 13.916s

113 packages are looking for funding
  run `npm fund` for details

found 36 vulnerabilities (27 moderate, 9 high)
  run `npm audit fix` to fix them, or `npm audit` for details