【问题标题】:GitHub action failed at npm ciGitHub 操作在 npm ci 失败
【发布时间】:2022-01-25 17:15:21
【问题描述】:

npm ci 在本地传递,但在作为 GitHub 操作的一部分运行以构建和部署到 Firebase 托管时失败。项目是 Angular 13。

错误是:npm ERR! The 'npm ci' command can only install with an existing package-lock.json

这是 yaml 配置文件:

# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge
'on':
  push:
    branches:
      - main
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: npm ci && npm run build
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_MY_WEBSITE }}'
          channelId: live
          projectId: my-website

【问题讨论】:

  • 您是否尝试过错误中的建议点?我认为您的.gitignore 文件中已排除package-lock.json
  • @Sysix package-lock.json 不在 .gitignore 中,它显示在 repo 中

标签: github github-actions


【解决方案1】:

您可以通过De Voorhoede关注“Super fast npm install on Github Actions Super fast npm install on Github Actions”:

    steps:
      - uses: actions/checkout@v2

      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '14'

      - name: Cache dependencies
        uses: actions/cache@v2
        with:
          path: ~/.npm
          key: npm-${{ hashFiles('package-lock.json') }}
          restore-keys: npm-

      - name: Install dependencies
        run: cd my-site && npm ci --ignore-scripts
             ^^^^^^^^^^^^

      # run npm test, build, lint, etc.

这样,package-lock.json 应该会正确生成。

如果您在正确的文件夹中,这应该可以工作,因为OP matchifang 添加了the comments

我发现我在错误的目录中。

【讨论】:

  • 我试过了,它在“安装依赖项”步骤中给了我这个错误:npm ERR! enoent ENOENT: no such file or directory, open '/home/runner/work/my-website/my-website/package.json'我需要在该步骤中更改任何内容吗?
  • 检查在签出时,您的存储库是否有 package.json 文件。
  • 我通读了日志,但我不知道在哪里可以找到已签出的文件。你能告诉我如何找到它吗?
  • @mat 在结帐步骤之后,我只需使用命令find . 执行 sh 步骤,以便列出当前文件夹中的所有文件
  • 我发现我在错误的目录中。谢谢! :D
猜你喜欢
  • 2022-01-10
  • 2021-11-13
  • 2021-10-06
  • 2021-10-03
  • 2023-02-14
  • 2022-01-03
  • 2021-11-14
  • 2021-10-01
  • 2023-02-25
相关资源
最近更新 更多