Site deploy failed - Fail on npm run build

These are the errors I am getting when deploying my GitHub web app created in React.
3:51:57 PM: $ npm run build
3:51:58 PM: npm
3:51:58 PM: ERR!
3:51:58 PM: code
3:51:58 PM: ENOENT
3:51:58 PM: npm
3:51:58 PM: ERR!
3:51:58 PM: syscall
3:51:58 PM: open
3:51:58 PM: npm
3:51:58 PM: ERR!
3:51:58 PM: path
3:51:58 PM: /opt/build/repo/package.json
3:51:58 PM: npm ERR! errno
3:51:58 PM: -2
3:51:58 PM: npm
3:51:58 PM: ERR! enoent ENOENT: no such file or directory, open β€˜/opt/build/repo/package.json’
3:51:58 PM: npm
3:51:58 PM: ERR!
3:51:58 PM: enoent
3:51:58 PM: This is related to npm not being able to find a file.
3:51:58 PM: npm
3:51:58 PM: ERR!
3:51:58 PM: enoent
3:51:58 PM: npm
3:51:58 PM: ERR! A complete log of this run can be found in:
3:51:58 PM: npm ERR! /opt/buildhome/.npm/_logs/2020-06-01T20_51_58_150Z-debug.log
3:51:58 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
3:51:58 PM: β”‚ β€œbuild.command” failed β”‚
3:51:58 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
3:51:58 PM: ​
3:51:58 PM: Error message
3:51:58 PM: Command failed with exit code 254: npm run build
3:51:58 PM: Error location
3:51:58 PM: In Build command from settings:
3:51:58 PM: npm run build
3:51:58 PM: Resolved config
3:51:58 PM: build:
3:51:58 PM: command: npm run build
3:51:58 PM: publish: /opt/build/repo/build
…
3:51:58 PM: Finished saving go dependencies
3:52:01 PM: Error running command: Build script returned non-zero exit code: 1
3:52:01 PM: Failing build: Failed to build site
3:52:01 PM: Failed during stage β€˜building site’: Build script returned non-zero exit code: 1
3:52:01 PM: Finished processing build request in 14.627895311s

By errors, I assume it’s an issue where npm run build doesn’t work because there’s no package.json file inside the build folder.

3:51:58 PM: Error message
3:51:58 PM: Command failed with exit code 254: npm run build

There is a package.json file on the root. When I do npm run build for the first time, it does create a build folder, but not a package.json file inside of it. Is that normal?

{
  "name": "mitch-portfolio",
  "version": "0.1.0",
  "private": false,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

GitHub: GitHub - mitchelln11/portfolio-repo
I’ve tried command line and the drag and drop build folder.

Anything will help.

There is not a package.json file in the root of your repository. It is in the folder β€˜mitch-portfolio’. You need to set the base directory in your Netlify site settings to β€˜mitch-portfolio’.

4 Likes

Hey, thanks, that’s it. Now I just need to figure out how to treat my local json files as rest apis.