Github 操作:npm install -> 错误:进程已完成,退出代码为 1

Posted

技术标签:

【中文标题】Github 操作:npm install -> 错误:进程已完成,退出代码为 1【英文标题】:Github action: npm install -> Error: Process completed with exit code 1 【发布时间】:2022-01-17 06:50:38 【问题描述】:

我的这个 GitHub 操作工作流已经运行了一年多。当我进入运行“npm install”的步骤时,突然出现错误。我真的不知道为什么会触发错误。非常感谢有人帮助或至少只是指出我正确的方向。如果您需要更多数据,请告诉我,我将编辑问题。

我已经尝试更新一些软件包以及npm update 命令。但不好:

Run npm install
npm WARN old lockfile 
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile 
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile 
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
npm WARN deprecated core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! path /home/runner/work/projsiteWebApp/projsiteWebApp/node_modules/node-sass
npm ERR! command failed
npm ERR! command sh -c node scripts/build.js
npm ERR! Building: /usr/local/bin/node /home/runner/work/projsiteWebApp/projsiteWebApp/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! make: Entering directory '/home/runner/work/projsiteWebApp/projsiteWebApp/node_modules/node-sass/build'
npm ERR!   g++ '-DNODE_GYP_MODULE_NAME=libsass' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '- 

(此处还有一些错误消息,但由于字符太多而不得不切断)

npm ERR!                                       remove_cv
npm ERR! /home/runner/.node-gyp/16.13.1/include/node/v8-internal.h:492:38: error: ‘remove_cv_t’ is not a member of ‘std’
npm ERR! /home/runner/.node-gyp/16.13.1/include/node/v8-internal.h:492:38: note: suggested alternative: ‘remove_cv’
npm ERR!              !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
npm ERR!                                       ^~~~~~~~~~~
npm ERR!                                       remove_cv
npm ERR! /home/runner/.node-gyp/16.13.1/include/node/v8-internal.h:492:50: error: template argument 2 is invalid
npm ERR!              !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
npm ERR!                                                   ^
npm ERR! /home/runner/.node-gyp/16.13.1/include/node/v8-internal.h:492:63: error: ‘::Perform’ has not been declared
npm ERR!              !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
npm ERR!                                                                ^~~~~~~
npm ERR! /home/runner/.node-gyp/16.13.1/include/node/v8-internal.h:492:63: note: suggested alternative: ‘herror’
npm ERR!              !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
npm ERR!                                                                ^~~~~~~
npm ERR!                                                                herror
npm ERR! make: *** [Release/obj.target/binding/src/binding.o] Error 1
npm ERR! gyp ERR! build error 
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/home/runner/work/projsiteWebApp/projsiteWebApp/node_modules/node-gyp/lib/build.js:262:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
npm ERR! gyp ERR! System Linux 5.4.0-1064-azure
npm ERR! gyp ERR! command "/usr/local/bin/node" "/home/runner/work/projsiteWebApp/projsiteWebApp/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd /home/runner/work/projsiteWebApp/projsiteWebApp/node_modules/node-sass
npm ERR! gyp ERR! node -v v16.13.1
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok 
npm ERR! Build failed with error code: 1

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-12-13T20_05_37_396Z-debug.log
Error: Process completed with exit code 1.

【问题讨论】:

【参考方案1】:

您的项目中似乎有一些东西正在使用 node-sass,其中包含已弃用的 libsass

如果是直接依赖,你可以直接切换到Dart Sass,大部分情况应该是一样的。如果它是需要node-sass 的传递依赖项,您可以尝试通过更新依赖它的直接依赖项来更新它。或者,如果你使用 yarn,你可以尝试change it with selective version resolutions

如果您无法切换到使用 dart-sass 并且必须处理 C++ gyp 构建错误,我可能会检查以确保您使用的特定版本的 node-sass 与当前已安装的当前 c++ 编译器。也许你的编译器太老了,因为libsass(反过来,node-sass)决定提高他们的语言要求?

编辑: 尝试使用 this technique(因为您使用的是 npm)将 vue-mj-daterangepicker 中的 node-sass 解析为其他内容。您可以更改为较新的版本或使用“dart-sass”包。如果你使用后者,g++ 不会出错,因为 dart-sass 不使用 c++。你也可以使用“sass”包,因为sassdart-sass npm 包本质上是一样的

在您的package.json...中可能类似于以下内容(未测试)

"resolutions": 
  "node-sass": "https://registry.npmjs.org/node-sass/-/node-sass-7.0.0.tgz"
,
"scripts": 
  "preinstall": "npx npm-force-resolutions"

"resolutions": 
  "node-sass": "https://registry.npmjs.org/dart-sass/-/dart-sass-1.25.0.tgz"
,
"scripts": 
  "preinstall": "npx npm-force-resolutions"

【讨论】:

没有 iam 使用 npm 而不是纱线。 node-sass 是传递依赖。我如何更新传递依赖项不知道您可以做到这一点。我尝试了“npm update node-sass”,但没有任何反应。顺便说一句,在我的 package.lock 中,如果我在 libsass 上搜索(ctrl+f),我什么也找不到。你真的认为这里的障碍是 libsass 吗? @edwin 非常感谢答案 哦,我刚刚看到你说通过更新依赖它的直接依赖项来更新它...会尝试 我认为 libsass 不会出现在您的 package-lock.json 中,因为它不是 npm 包; node-sass 应该在那里。 npm update node-sass 可能不起作用,因为它不是直接依赖项。同样对于 npm,似乎有 something 用于固定传递依赖项,但我不确定它的效果如何 更清楚一点,我认为这是node-sass 的问题。如果使用 dart-sass 包而不是 node-sass,则不必编译 libsass,您也不会遇到那些 g++ 错误 是的,我更新了 node-sass。使用你的第一个例子。奇迹般有效。你我的家伙是国王!【参考方案2】:

发生这种情况的原因是因为 libsass 在构建时似乎设置为使用 C++11 标准,但 std::remove_cv_t 仅作为 C++14 标准的一部分引入(我认为某些编译器像 MSVC 可能比这更早引入它)。一个简单的解决方法是在运行 npm install 之前设置 CXXFLAGS 环境变量。例如CXXFLAGS="--std=c++14" npm install

【讨论】:

以上是关于Github 操作:npm install -> 错误:进程已完成,退出代码为 1的主要内容,如果未能解决你的问题,请参考以下文章

`npm install` 以“Killed”结尾

为啥 yarn install checkout github 存储库依赖项但 npm install 没有?

npm install

npm install 不在 GitHub 上安装最新版本

Docker `npm install` 与 TypeScript 中的 GitHub 私有 repo 依赖项

thingsboard编译错误 Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.0:npm (npm instal