GitHub 操作在 npm ci 上失败

Posted

技术标签:

【中文标题】GitHub 操作在 npm ci 上失败【英文标题】:GitHub action fails on npm ci 【发布时间】:2022-01-10 00:25:16 【问题描述】:

我有 git 操作来运行更漂亮(代码格式化程序)。下面是 git action 的format.yml 文件。

name: Format code with prettier
on:
  push:
    branches-ignore:
      - master
jobs:
  format:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      # Install NPM dependencies, cache them correctly
      - name: Run prettier
        run: |
          npm ci
          npm run prettier-check

下面列出了我遇到的错误。

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 EBADENGINE Unsupported engine 
npm WARN EBADENGINE   package: 'react-lottie@1.2.3',
npm WARN EBADENGINE   required:  npm: '^3.0.0' ,
npm WARN EBADENGINE   current:  node: 'v16.13.0', npm: '8.1.0' 
npm WARN EBADENGINE 
...
npm ERR! code 1
npm ERR! path /home/runner/work/Web/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/Web/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/Web/node_modules/node-sass/build'
npm ERR!   g++ '-DNODE_GYP_MODULE_NAME=libsass' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_GLIBCXX_USE_CXX11_ABI=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-D__STDC_FORMAT_MACROS' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DLIBSASS_VERSION="3.5.5"' -I/home/runner/.node-gyp/16.13.0/include/node -I/home/runner/.node-gyp/16.13.0/src -I/home/runner/.node-gyp/16.13.0/deps/openssl/config -I/home/runner/.node-gyp/16.13.0/deps/openssl/openssl/include -I/home/runner/.node-gyp/16.13.0/deps/uv/include -I/home/runner/.node-gyp/16.13.0/deps/zlib -I/home/runner/.node-gyp/16.13.0/deps/v8/include -I../src/libsass/include  -fPIC -pthread -Wall -Wextra -Wno-unused-parameter -m64 -O3 -fno-omit-frame-pointer -std=gnu++14 -std=c++0x -fexceptions -frtti -MMD -MF ./Release/.deps/Release/obj.target/libsass/src/libsass/src/ast.o.d.raw   -c -o Release/obj.target/libsass/src/libsass/src/ast.o ../src/libsass/src/ast.cpp
...
npm ERR! gyp verb extracted file from tarball include/node/uv/os390.h
npm ERR! gyp verb extracted file from tarball include/node/uv/posix.h
npm ERR! gyp verb extracted file from tarball include/node/uv/stdint-msvc2008.h
npm ERR! gyp verb extracted file from tarball include/node/uv/sunos.h
npm ERR! gyp verb extracted file from tarball include/node/uv/threadpool.h
npm ERR! gyp verb extracted file from tarball include/node/uv/unix.h
npm ERR! gyp verb extracted file from tarball include/node/uv/win.h
npm ERR! gyp verb extracted file from tarball include/node/uv/errno.h
npm ERR! gyp verb extracted file from tarball include/node/uv/tree.h
npm ERR!
Error: Process completed with exit code 1.

以前使用过的 Git 操作 yml 文件。我没有更改任何版本/包锁定文件。尽管如此,它还是失败了。任何人都可以从错误日志中提出解决方案吗?

【问题讨论】:

【参考方案1】:

看来您在 githubAction 中运行的是不同的节点版本。

设置与之前使用本地相同的节点版本(例如 14)以运行npm ci

- uses: actions/setup-node@v2
  with:
    node-version: '14'
- name: Run prettier
  run: |
    npm ci
    npm run prettier-check
...

【讨论】:

以上是关于GitHub 操作在 npm ci 上失败的主要内容,如果未能解决你的问题,请参考以下文章

npm 错误!在 github 操作上构建脚本期间失败

Github 操作 ci cd 失败

Npm install 在 github 操作中失败

Gitlab CI 失败:未找到 NPM 命令

从 Github 包注册表安装私有包失败,未找到/未授权

GitHub Actions 与 Jenkins 等其他 CI 工具有啥区别?