npm install in GitHub Action fails with“ENOENT:没有这样的文件或目录”-在其他地方工作正常

3lxsmp7m  于 2023-08-06  发布在  Git
关注(0)|答案(4)|浏览(149)

我目前正在使用GitHub Actions替换我们的Drone CI安装。
到目前为止,我的操作工作流可以归结为以下.github/workflows/ci.yml文件:

on: [ push, pull_request ]

name: CI
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Install Node
        uses: actions/setup-node@v1
        with:
          node-version: '13.x'

      - name: Install Dependencies
        run: npm install

字符串
日志本身以一长串npm WARN tar ENOENT: no such file or directory的形式出现在下面的截断列表中。

2020-04-29T21:15:31.7899082Z npm install
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/acorn-26d8ba97/dist/acorn.js.map'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/coffeescript-acee515b/lib/coffee-script/register.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/coffeescript-acee515b/lib/coffee-script/repl.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/coffeescript-acee515b/lib/coffee-script/rewriter.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/tslint-c216b578/LICENSE'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/eslint-cd3dbe58/LICENSE'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/eslint-cd3dbe58/README.md'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/typescript-b4b55d18/lib/diagnosticMessages.generated.json'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/jquery-1794793b/dist/jquery.min.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/lodash-05c1df31/fp/_convertBrowser.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/lodash-70e4a396/fp/_convertBrowser.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/lodash-79f5ae17/fp/_convertBrowser.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/lodash-e49b02f6/fp/_convertBrowser.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/lodash-16fa050d/fp/_convertBrowser.js'


我在网上找到的建议是rm package-lock.json,但这不是一个可接受的解决方案,因为我需要用我们锁定的依赖项的确切版本来测试我们的代码。
此外,我不相信我们的package-lock.json文件有任何问题,因为它仍然是npm install,正如本地和我们的Drone CI安装所期望的那样。

gywdnpxw

gywdnpxw1#

在漫长的等待中,我找到了解决方案:
使用GitHub Actions从私有GitHub存储库安装npm模块

- uses: actions/checkout@v2
        with:
          persist-credentials: false
      - uses: actions/setup-node@v1
        with:
          node-version: 12.x
      - run: git config --global url."https://${{ secrets.PAT }}@github.com/".insteadOf ssh://git@github.com/
      - run: npm ci
      ...

字符串
我自己基本上都试过了,但最重要的部分却没有:

with:
          persist-credentials: false


默认情况下,actions/checkout@v2会扰乱Git的一些设置,并阻止insteadOf正常工作。

zzoitvuj

zzoitvuj2#

如果您使用的是私有npm包,并且忘记将secret添加到repo中,也会发生这种错误情况。
例如,如果你在GitHub Actions工作流中有这样的东西:

- name: Add token for private package access to .npmrc
  run: echo "//npm.pkg.github.com/:_authToken=$ACME_CORP_TOKEN" > ~/.npmrc
  env:
    ACME_CORP_TOKEN: ${{ secrets.ACME_CORP_TOKEN }}

字符串
.如果$ACME_CORP_TOKEN不存在,像上面这样的操作不会失败(尽管这样做会更好),所以如果你忘记了实际添加ACME_CORP_TOKEN秘密到存储库(在存储库设置的Secrets选项卡中),那么你会遇到同样的问题。
node_modules内部的普通依赖项的npm WARN tar ENOENT错误的巨大列表不会使问题实际上是缺少私有注册表访问令牌变得明显。

iklwldmw

iklwldmw3#

我们有这个问题。在无休止的tar ENOENT错误流中,我们发现了另一个错误(为简洁起见编辑):

npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git@github.com/fivetran/doctrine.git
npm ERR! git@github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR! exited with error code: 128

字符串
在我们的例子中,有问题的存储库是公共的,但是无论出于什么原因,npm仍然试图通过ssh而不是https获取它(不像我们所有其他的依赖项)。
我们通过在工作流中添加一个额外的步骤来解决这个问题,将npm配置为使用https:

steps:
    - uses: actions/checkout@v2
      with:
        persist-credentials: false

    - name: Reconfigure git to use HTTP authentication
      run: >
        git config --global url."https://github.com/".insteadOf
        ssh://git@github.com/

    # etc.

mrwjdhj3

mrwjdhj34#

在我的例子中,其中一个文件已从Pascal大小写重命名为小写:
首页.vue =>首页
由于未知原因,此更改尚未复制到GitHub存储库。(我以前在Windows系统上见过这种情况,但在我的Mac上没有)。我的解决方案是重命名该文件和对它的相应引用:
首页.vue =>首页.vue

相关问题