【问题标题】:"npm install" in Github Actions failedGithub 操作中的“npm install”失败
【发布时间】:2021-10-03 13:20:25
【问题描述】:

我尝试创建一个在 ./example 文件夹上运行的 github 操作。 /.example 文件夹中的代码是使用 create-react-app 构建的。

工作流程代码:

name: CI

on:
  push:
    branches: [ origin ]
  pull_request:
    branches: [ origin ]

jobs:
  build_test:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x, 15.x]

    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
      - name: npm install, build, and test example
        working-directory: example
        run: |
          npm install
          npm run build --if-present

但它会导致错误:

我的项目结构(./example里面有package.json):

【问题讨论】:

  • 您能分享您的项目(如果它是公开的)以在 fork 上测试工作流程吗?

标签: npm continuous-integration create-react-app github-actions


【解决方案1】:

您的工作流程 yaml 文件应如下所示。

name: CI

on:
  push:
    branches: [ origin ]
  pull_request:
    branches: [ origin ]

jobs:
  build_test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [10.x, 15.x]
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
      - name: npm install, build, and test example
        working-directory: ./example
        run: |
          npm install
          npm run build --if-present

【讨论】:

  • 不幸的是,它不起作用:npm ERR! Could not install from "../node_modules/@types/node" as it does not contain a package.json file.
  • 您是否安装了任何本地依赖项?因为我觉得这不是因为 NPM 没有找到 package.json。请在下面找到参考链接github.com/npm/npm/issues/18266。如果 NPM 没有找到你的 package.json 它会抛出下面的错误,no such file or directory, open '/example/package.json'
  • v2 版本是否支持工作目录标签?
猜你喜欢
  • 2021-10-06
  • 2022-01-25
  • 2023-02-14
  • 2022-01-10
  • 1970-01-01
  • 2016-01-22
  • 2022-01-03
  • 2021-10-01
  • 2021-12-05
相关资源
最近更新 更多