首页 > 解决方案 > Github 的操作不是构建 React 应用程序

问题描述

当我构建时 (npm run build "scripts": { "build": "react-scripts build --passWithNoTests" }

) 项目在 pc 上,它成功构建。但是当我推送更改时,构建过程在 github 上失败了

> log@0.1.0 build /home/runner/work/project/project
> react-scripts build --passWithNoTests

Creating an optimized production build...

Treating warnings as errors because process.env.CI = true.
Most CI servers set it automatically.

Failed to compile.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! log@0.1.0 build: `react-scripts build --passWithNoTests`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the log@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2020-08-17T06_51_55_527Z-debug.log
##[error]Process completed with exit code 1.

这是yml文件

name: Node.js CI
on:
  push:
    branches: [ test ]
  pull_request:
    branches: [ test ]

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest

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

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
      
    - name: clean cache
      run: npm cache clean --force
    - name: install
      run: npm ci
    - name: npm install
      run: npm install
    - name: build
      run: npm run test --if-present

我该怎么做?

标签: node.jsreactjsgithubnpmgithub-actions

解决方案


GitHub ActionsCI使用true. 因此将警告视为错误。您可以尝试如下。

- name: build
  run: npm run test --if-present
  env:
     CI: false

快乐的自动化!


推荐阅读