1

I tried to deploy my react app to the droplet in the digital ocean using Github action, but I faced a problem when Github Action try to run the build command, it always throws an error:

Run npm run build
  
npm ERR! Missing script: "build"
npm ERR! 
npm ERR! To see a list of scripts, run:
npm ERR!   npm run

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/gli/.npm/_logs/2022-11-24T06_58_48_588Z-debug-0.log
Error: Process completed with exit code 1.

My package.json file, I do not know why since I also have a build script in the package.json file as well.

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

Github Action node.js.yml

name: Node.js CI

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: self-hosted

    strategy:
      matrix:
        node-version: [16.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm i
    - run: cd frontend
    - run: npm i
    - run: npm run build # fail here......:(
    - run: cd ..
    - run: pm2 stop 0
    - run: pm2 start 0
    - run: pm2 save
    - run: sudo service nginx restart

Note: Other commands are running fine only the run: npm run build is fail. Does anyone know what the problem is? I would appreciate your help and advice.

Jonh
  • 95
  • 1
  • 2
  • 13
  • Is your `package.json` in the `frontend` folder or is it a level up? – Ed Kloczko Nov 26 '22 at 19:05
  • Thank you for your comment. My packet.json is inside the frontend folder, that's why I run ```cd frontend``` before ```npm run build```. What exactly is wrong? – Jonh Nov 27 '22 at 04:15
  • Try replacing the 3 steps after the first `npm i` with `cd frontend && npm i && npm run build`. I can't remember the behavior but I have a feeling each `run` step will start from the home directory unless you specify a [`working-directory`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun) in the step. – Ed Kloczko Nov 27 '22 at 15:57

0 Answers0