提问者:小点点

Cypress Github操作失败


我将GitHub操作用于CI/CD,并从中编写了一些cypress测试和YAML文件。但是当我推存储库时,我得到了一个错误。

name: Cypress Tests

# Controls when the workflow will run
on:
 # Triggers the workflow on push or pull request events but only for the main branch
push:
  branches: [ main ]

jobs:
  cypress-run:
    runs-on: ubuntu-latest
     steps:
      - name: Checkout
     uses: actions/checkout@v2
     # Install NPM dependencies, cache them correctly
     # and run all Cypress tests
     - name: Cypress run
       uses: cypress-io/github-action@v2
       with:
         build: npm run build
         start: npm start

失败的错误

./src/App.scss
Node Sass version 6.0.1 is incompatible with ^4.0.0 || ^5.0.0.


npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reversed-spider-solitaire@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the reversed-spider-solitaire@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/2021-08-22T20_28_01_743Z-debug.log

Error: The process '/usr/local/bin/npm' failed with exit code 1

我如何解决这个问题。当我在本地运行cypress时,它工作正常。


共2个答案

匿名用户

你需要把第一步设置节点版本。

- name: Setup Node
      uses: actions/setup-node@v1
      with:
        node-version: 15

匿名用户

这个问题与github操作没有直接关系,而是与从缓存中提取它的cypress操作使用的节点版本和您在应用程序中使用的节点sass版本有关。根据错误消息,您应该能够使用12和16之间的任何节点版本(最新)每个节点sass包自述文件https://www.npmjs.com/package/node-sass

有关更多信息,请查看此post错误:节点Sass版本5.0。0与^4.0不兼容。0

在这个演示中,您可以看到cypress利用动作的示例正常工作,这让您知道这不是github动作或cypress设置https://github.com/meroware/demo-cypress-github-action

进行以下更改,您就可以开始了

name: Cypress Tests
on:
  push:
    branches: [ main ]
jobs:
  cypress-run:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup Node
        uses: actions/setup-node@v1
        with:
          node-version: 14 # but you can do 12-16
      - name: Cypress run
        uses: cypress-io/github-action@v2.3.6
        with:
          build: npm run build
          start: npm start