【问题标题】:Github action script must install npm first to install packages yet others scripts don't requireGithub 操作脚本必须先安装 npm 才能安装软件包,而其他脚本不需要
【发布时间】:2021-11-15 06:56:15
【问题描述】:

这是下面的工作脚本。困扰我的部分是:

    - name: install npm
      run: npm i npm@latest
      working-directory: ./functions

我必须安装最新版本的 NPM,否则我会收到此错误:

npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

忽略此错误不会安装我需要运行 Firebase 功能的 npm 包。我有其他不需要这种手持的 github 动作脚本。我在这里做错了什么?

完整脚本:

name: Deploy to Firebase Functions

on:
  push:
    branches:
      - main
    # Optionally configure to run only for specific files. For example:
    paths:
    - "functions/**"

jobs:
  main:
    name: Deploy
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js 14
      uses: actions/setup-node@v2
      with:
        node-version: '14'
    - name: install npm
      run: npm i npm@latest
      working-directory: ./functions
    - name: install libraries
      run: npm i
      working-directory: ./functions
    - name: install firebase
      run: npm i firebase-tools -g
    - name: deploy
      run: firebase deploy --only functions --token ${{ secrets.FIREBASE_FUNCTIONS_TOKEN }}
      working-directory: ./functions

【问题讨论】:

    标签: npm npm-install github-actions


    【解决方案1】:

    问题是,生成package-lock.jsonnpm 版本与Node.js V14 中包含的npm 版本不兼容。

    第一个选项可能是在 CI 中使用此类 Node.js 版本,该版本已包含与 lockfileVersion@2 兼容的此类 npm 版本。但是,npm version 7 支持 lockfileVersion@2,它是 the latest Node.js 版本的一部分。由于未来的安全更新,使用 LTS 版本的 Node 是更好的选择,因此我不推荐此选项。

    作为第二个选项,packgage-lock.json 可以使用带有npm V6 的Node.js LTS 版本重新生成。这样,lockfileVersion 就可以用于 Node 版本 14(现在是 LTS 版本)的 CI。我认为这是最好的选择。

    作为第三个选项,一个想法是尝试npm ci 命令,但我不确定这是否适用于这种情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-13
      • 2018-03-15
      • 1970-01-01
      • 2019-03-19
      • 1970-01-01
      • 2017-03-10
      • 1970-01-01
      • 2020-05-19
      相关资源
      最近更新 更多