首页 > 解决方案 > Github 操作中的“npm install”失败

问题描述

我试图创建一个在./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):

在此处输入图像描述

标签: npmcontinuous-integrationcreate-react-appgithub-actions

解决方案


您的工作流程 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

推荐阅读