Home > Blockchain >  How to fix missing build script using cypress github actions?
How to fix missing build script using cypress github actions?

Time:10-19

I have tried to add a github action, which is supposed to test my app using cypress.

This is what my workflowfile looks like:

name: Cypress Tests

on: [push]

jobs:
  cypress-run:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./client
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      # Install NPM dependencies, cache them correctly
      # and run all Cypress tests
      - name: Setup Node
        uses: actions/setup-node@v1
        with:
          node-version: 14
      - name: Test
        run: |
          ls
          cat package.json
      - name: Cypress run
        uses: cypress-io/[email protected]
        with:
          build: npm run build
          start: npm start
      - name: Test
        run: ls

The Test step contains cat package.json which shows, the package.json file, which looks like this:

{
    "name": "client",
    "version": "0.1.0",
    "private": true,
    "scripts": {
        "dev": "next dev",
        "build": "next build",
        "start": "next start",
        "lint": "next lint",
        "cypress:open": "cypress open",
        "cypress:run": "cypress run"
    },
    "dependencies": {
        "@reduxjs/toolkit": "^1.6.1",
        "axios": "^0.21.4",
        "framer-motion": "^4.1.17",
        "next": "11.1.2",
        "phosphor-react": "^1.3.1",
        "qs": "^6.10.1",
        "react": "17.0.2",
        "react-dom": "17.0.2",
        "react-leaflet": "^3.2.1",
        "react-redux": "^7.2.5",
        "uuid": "^8.3.2",
        "cypress": "^8.6.0"
    },
    "devDependencies": {
        "autoprefixer": "^10.3.4",
        "cypress": "^8.6.0",
        "eslint": "7.32.0",
        "eslint-config-next": "11.1.2",
        "postcss": "^8.3.6",
        "tailwindcss": "^2.2.15"
    }
}

As you can see there is a build script, however when the workflow runs it throws this error:

build app command "npm run build"
current working directory "/home/runner/work/mlc/mlc"
/opt/hostedtoolcache/node/14.18.0/x64/bin/npm run build
npm ERR! missing script: build

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-10-17T11_04_01_715Z-debug.log
Error: The process '/opt/hostedtoolcache/node/14.18.0/x64/bin/npm' failed with exit code 1

I have no idea why this happens, since the package.json sort of proves, that there is a build script.

CodePudding user response:

I had the same error, the answer is quite easy, however I haven't found it in a single documentation yet.

You have to add: working-directory: client after with: inside Cypress run like this:

-

name: Cypress Tests
   
   on: [push]
   
   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:
             working-directory: client
             build: npm run build
             start: npm start
  • Related