Build script returned "Command failed with exit code 1: npm build"

Hi, I new on Netlify and I built two sites from my github.

But when I did try the third site, I got this error msg and the build failed.

The app is running ok on my pc (I did clone few mins ago the repository localy and tested)

The site name with this issue: effulgent-sable-420f23
PLEASE help us help you by writing a good post!

7:14:05 PM: build-image version: d55944c047ef0aee2ac01971edde72cb2a50acfe (focal)
7:14:05 PM: build-image tag: v4.16.1
7:14:05 PM: buildbot version: 0be68edd034c744ad79b207db44f42646b4e8ecb
7:14:05 PM: Fetching cached dependencies
7:14:05 PM: Failed to fetch cache, continuing with build
7:14:05 PM: Starting to prepare the repo for build
7:14:05 PM: No cached dependencies found. Cloning fresh repo
7:14:05 PM: git clone https://github.com/prtpj1/recipes-app
7:14:05 PM: Preparing Git Reference refs/heads/main
7:14:06 PM: Parsing package.json dependencies
7:14:07 PM: Starting build script
7:14:07 PM: Installing dependencies
7:14:07 PM: Python version set to 2.7
7:14:08 PM: v16.19.0 is already installed.
7:14:08 PM: Now using node v16.19.0 (npm v8.19.3)
7:14:08 PM: Enabling node corepack
7:14:08 PM: Started restoring cached build plugins
7:14:08 PM: Finished restoring cached build plugins
7:14:08 PM: Attempting ruby version 2.7.2, read from environment
7:14:09 PM: Using ruby version 2.7.2
7:14:09 PM: Using PHP version 8.0
7:14:09 PM: Started restoring cached yarn cache
7:14:09 PM: Finished restoring cached yarn cache
7:14:10 PM: No yarn workspaces detected
7:14:10 PM: Started restoring cached node modules
7:14:10 PM: Finished restoring cached node modules
7:14:10 PM: Installing NPM modules using Yarn version 1.22.19
7:14:10 PM: yarn install v1.22.19
7:14:10 PM: warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
7:14:10 PM: [1/5] Validating package.json...
7:14:10 PM: [2/5] Resolving packages...
7:14:11 PM: [3/5] Fetching packages...
7:14:25 PM: warning console@0.5.2: The engine "ender" appears to be invalid.
7:14:25 PM: [4/5] Linking dependencies...
7:14:25 PM: warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5".
7:14:25 PM: warning " > bootstrap@4.6.1" has unmet peer dependency "jquery@1.9.1 - 3".
7:14:25 PM: warning " > bootstrap@4.6.1" has unmet peer dependency "popper.js@^1.16.1".
7:14:25 PM: warning "react-scripts > tailwindcss@3.0.16" has unmet peer dependency "autoprefixer@^10.0.2".
7:14:25 PM: warning "react-scripts > eslint-config-react-app > eslint-plugin-flowtype@8.0.3" has unmet peer dependency "@babel/plugin-syntax-flow@^7.14.5".
7:14:25 PM: warning "react-scripts > eslint-config-react-app > eslint-plugin-flowtype@8.0.3" has unmet peer dependency "@babel/plugin-transform-react-jsx@^7.14.9".
7:14:25 PM: warning "react-scripts > react-dev-utils > fork-ts-checker-webpack-plugin@6.5.0" has unmet peer dependency "typescript@>= 2.7".
7:14:25 PM: warning "react-scripts > webpack-dev-server > http-proxy-middleware@2.0.2" has unmet peer dependency "@types/express@^4.17.13".
7:14:25 PM: warning "react-scripts > eslint-config-react-app > @typescript-eslint/eslint-plugin > tsutils@3.21.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
7:14:37 PM: [5/5] Building fresh packages...
7:14:47 PM: success Saved lockfile.
7:14:47 PM: Done in 36.36s.
7:14:47 PM: NPM modules installed using Yarn
7:14:47 PM: Started restoring cached go cache
7:14:47 PM: Finished restoring cached go cache
7:14:48 PM: go version go1.19.4 linux/amd64
7:14:48 PM: Detected 1 framework(s)
7:14:48 PM: "create-react-app" at version "5.0.0"
7:14:48 PM: Installing missing commands
7:14:48 PM: Verify run directory
7:14:48 PM: Section completed: initializing
7:14:49 PM: ​
7:14:49 PM:   Netlify Build                                                 
7:14:49 PM: ────────────────────────────────────────────────────────────────
7:14:49 PM: ​
7:14:49 PM: ❯ Version
7:14:49 PM:   @netlify/build 29.2.1
7:14:49 PM: ​
7:14:49 PM: ❯ Flags
7:14:49 PM:   baseRelDir: true
7:14:49 PM:   buildId: 63acbfab49a6af10bacc0f26
7:14:49 PM:   deployId: 63acbfab49a6af10bacc0f28
7:14:50 PM: ​
7:14:50 PM: ❯ Current directory
7:14:50 PM:   /opt/build/repo
7:14:50 PM: ​
7:14:50 PM: ❯ Config file
7:14:50 PM:   No config file was defined: using default values.
7:14:50 PM: ​
7:14:50 PM: ❯ Context
7:14:50 PM:   production
7:14:50 PM: ​
7:14:50 PM:   1. Build command from Netlify app                             
7:14:50 PM: ────────────────────────────────────────────────────────────────
7:14:50 PM: ​
7:14:50 PM: $ npm build
7:14:50 PM: Unknown command: "build"
7:14:50 PM: Did you mean this?
7:14:50 PM:     npm run build # run the "build" package script
7:14:50 PM: To see a list of supported npm commands, run:
7:14:50 PM:   npm help
7:14:50 PM: ​
7:14:50 PM:   "build.command" failed                                        
7:14:50 PM: ────────────────────────────────────────────────────────────────
7:14:50 PM: ​
7:14:50 PM:   Error message
7:14:50 PM:   Command failed with exit code 1: npm build
7:14:50 PM: ​
7:14:50 PM:   Error location
7:14:50 PM:   In Build command from Netlify app:
7:14:50 PM:   npm build
7:14:50 PM: ​
7:14:50 PM:   Resolved config
7:14:50 PM:   build:
7:14:50 PM:     command: npm build
7:14:50 PM:     commandOrigin: ui
7:14:50 PM:     publish: /opt/build/repo/build
7:14:50 PM:     publishOrigin: ui
7:14:50 PM: Caching artifacts
7:14:50 PM: Started saving node modules
7:14:50 PM: Finished saving node modules
7:14:50 PM: Started saving build plugins
7:14:50 PM: Finished saving build plugins
7:14:50 PM: Started saving yarn cache
7:14:53 PM: Finished saving yarn cache
7:14:53 PM: Started saving pip cache
7:14:53 PM: Finished saving pip cache
7:14:53 PM: Started saving emacs cask dependencies
7:14:53 PM: Finished saving emacs cask dependencies
7:14:53 PM: Started saving maven dependencies
7:14:53 PM: Finished saving maven dependencies
7:14:53 PM: Started saving boot dependencies
7:14:53 PM: Finished saving boot dependencies
7:14:53 PM: Started saving rust rustup cache
7:14:53 PM: Finished saving rust rustup cache
7:14:53 PM: Started saving go dependencies
7:14:53 PM: Finished saving go dependencies
7:14:54 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
7:14:54 PM: Failing build: Failed to build site
7:14:54 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
7:14:54 PM: Finished processing build request in 49.268700281s

Hi, @prtpj1. To run the build script in package.json the command would be this:

npm run build

However, your command is this:

npm build

If you add run to the command, it should begin working. If not, please let us know.

Hi Luke, thx for the answer, but I got a problem

I didnt create this package.json. It was created by the people where I’m studing programing and yet I only know a few things about create a package.json

“My” package.json is this:

{
  "name": "recipes-app-test",
  "version": "0.1.0",
  "private": true,
  "engines": {
    "node": "16"
  },
  "dependencies": {
    "@sheerun/mutationobserver-shim": "^0.3.3",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "axios": "^0.21.1",
    "bootstrap": "^4.5.3",
    "clipboard-copy": "^3.1.0",
    "eslint-plugin-sonarjs": "^0.11.0",
    "history": "^4.7.2",
    "lodash": "^4.17.15",
    "prop-types": "^15.7.2",
    "react": "^16.13.1",
    "react-bootstrap": "^1.4.0",
    "react-dom": "^16.13.1",
    "react-icons": "^4.3.1",
    "react-logger": "^1.1.0",
    "react-responsive-carousel": "^3.2.23",
    "react-router-dom": "^5.1.2",
    "react-scripts": "5.0.0",
    "websocket-extensions": ">=0.1.4"
  },
  "scripts": {
    "cy": "cypress run",
    "cy:open": "cypress open",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "test-coverage": "react-scripts test --coverage --watchAll=false",
    "eject": "react-scripts eject",
    "lint": "eslint --no-inline-config --no-error-on-unmatched-pattern -c .eslintrc.json . --ext .js,.jsx",
    "lint:styles": "npx stylelint '**/*.css'"
  },
  "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"
    ]
  },
  "devDependencies": {
    "clipboardy": "^2.1.0",
    "cypress": "^9.3.1",
    "cypress-multi-reporters": "^1.4.0",
    "eslint": "7.11.0",
    "eslint-config-trybe-frontend": "1.2.3",
    "eslint-plugin-react-hooks": "^4.2.0",
    "fs-extra": "^9.0.1",
    "mocha": "^8.0.1",
    "mochawesome": "^6.1.1",
    "mochawesome-merge": "^4.1.0",
    "mochawesome-report-generator": "^5.1.0",
    "stylelint": "^13.8.0",
    "stylelint-order": "^4.1.0"
  },
  "jest": {
    "coveragePathIgnorePatterns": [
      "src/index.js",
      "serviceWorker.js"
    ],
    "coverageReporters": [
      "json",
      "lcovonly",
      "text",
      "clover",
      "html"
    ]
  }
}

I tried to add the “run” to script “buiild”

"run build": "react-scripts build",

and I got another error(i dont know if was the correct thing, as I couldnt find another script for build.

[14:41:32.002] Cloning github.com/prtpj1/recipes-app (Branch: main, Commit: 77b1a8b)
[14:41:32.235] Previous build cache not available
[14:41:32.431] Cloning completed: 428.366ms
[14:41:32.845] Running "vercel build"
[14:41:33.315] Vercel CLI 28.10.0
[14:41:34.803] [3/5] Fetching packages...
[14:41:48.772] warning console@0.5.2: The engine "ender" appears to be invalid.
[14:41:48.798] [4/5] Linking dependencies...
[14:41:48.800] warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5".
[14:41:48.800] warning " > bootstrap@4.6.1" has unmet peer dependency "jquery@1.9.1 - 3".
[14:41:48.800] warning " > bootstrap@4.6.1" has unmet peer dependency "popper.js@^1.16.1".
[14:41:48.803] warning "react-scripts > tailwindcss@3.0.16" has unmet peer dependency "autoprefixer@^10.0.2".
[14:41:48.805] warning "react-scripts > eslint-config-react-app > eslint-plugin-flowtype@8.0.3" has unmet peer dependency "@babel/plugin-syntax-flow@^7.14.5".
[14:41:48.805] warning "react-scripts > eslint-config-react-app > eslint-plugin-flowtype@8.0.3" has unmet peer dependency "@babel/plugin-transform-react-jsx@^7.14.9".
[14:41:48.808] warning "react-scripts > react-dev-utils > fork-ts-checker-webpack-plugin@6.5.0" has unmet peer dependency "typescript@>= 2.7".
[14:41:48.809] warning "react-scripts > webpack-dev-server > http-proxy-middleware@2.0.2" has unmet peer dependency "@types/express@^4.17.13".
[14:41:48.813] warning "react-scripts > eslint-config-react-app > @typescript-eslint/eslint-plugin > tsutils@3.21.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[14:42:08.118] [5/5] Building fresh packages...
[14:42:17.738] success Saved lockfile.
[14:42:17.741] Done in 43.53s.
[14:42:18.783] Creating an optimized production build...
[14:42:18.875] Browserslist: caniuse-lite is outdated. Please run:
[14:42:18.875]   npx browserslist@latest --update-db
[14:42:18.875]   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[14:42:38.771] Browserslist: caniuse-lite is outdated. Please run:
[14:42:38.771]   npx browserslist@latest --update-db
[14:42:38.771]   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[14:42:40.426] Failed to compile.
[14:42:40.427] 
[14:42:40.427] Failed to load config "react-app" to extend from.
[14:42:40.427] Referenced from: /vercel/path0/package.json
[14:42:40.427] 
[14:42:40.427] 
[14:42:40.492] Error: Command "react-scripts build" exited with 1

I tried to look in ./node_modules/react-scripts, but there are so many things and I was a little dazy