Github 的动作不是构建 React 应用程序

Vla*_*yan 4 github node.js npm reactjs github-actions

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

) 项目,它成功构建。但是当我推送更改时,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.

Run Code Online (Sandbox Code Playgroud)

这是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
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

小智 14

GitHub ActionsCI自动设置环境变量true。因此将警告视为错误。您可以尝试如下。

- name: build
  run: npm run test --if-present
  env:
     CI: false
Run Code Online (Sandbox Code Playgroud)

快乐的自动化!

  • **更新我自己的评论:** 重要的是“env: CI: false”(具有正确的缩进)位于运行“npm run build”命令而不是“npm run test”的同一“run”步骤下。不确定OP是否打错字或者他的问题与我的问题完全不同,但这至少对我有用。 (4认同)