Netlify not building - Command failed with exit code 1: npm run build

Sorry. I dont understand. I have the same problem. I have to put [build]
command = “CI= npm run build” in netlify.toml? because the issue still persist

Can you explain how you did it?

hi there, please see this thread:

there are some instructions a few posts down from the top :+1:

4 Likes

This works! thank you very much!

2 Likes

Woooooo, thank you so much for this solution!!!

1 Like

thank you so much…

1 Like

Hey, i tried the CI= npm run build but it isnt working.

6:20:25 AM: ┌───────────────────────────────────┐
6:20:25 AM: │ 1. Build command from Netlify app │
6:20:25 AM: └───────────────────────────────────┘
6:20:25 AM: ​
6:20:25 AM: $ CI=npm run build
6:20:25 AM: bash: run: command not found
6:20:25 AM: ​
6:20:25 AM: ┌─────────────────────────────┐
6:20:25 AM: │ “build.command” failed │
6:20:25 AM: └─────────────────────────────┘
6:20:25 AM: ​
6:20:25 AM: Error message
6:20:25 AM: Command failed with exit code 127: CI=npm run build
6:20:25 AM: ​
6:20:25 AM: Error location
6:20:25 AM: In Build command from Netlify app:
6:20:25 AM: CI=npm run build
6:20:25 AM: ​
6:20:25 AM: Resolved config
6:20:25 AM: build:
6:20:25 AM: command: CI=npm run build
6:20:25 AM: commandOrigin: ui
6:20:25 AM: publish: /opt/build/repo/build
6:20:25 AM: Caching artifacts

1 Like

Hey i tried “CI= npm run build” but it didnt work.

Here is the error:

6:20:25 AM: ┌───────────────────────────────────┐
6:20:25 AM: │ 1. Build command from Netlify app │
6:20:25 AM: └───────────────────────────────────┘
6:20:25 AM: ​
6:20:25 AM: $ CI=npm run build
6:20:25 AM: bash: run: command not found
6:20:25 AM: ​
6:20:25 AM: ┌─────────────────────────────┐
6:20:25 AM: │ “build.command” failed │
6:20:25 AM: └─────────────────────────────┘
6:20:25 AM: ​
6:20:25 AM: Error message
6:20:25 AM: Command failed with exit code 127: CI=npm run build
6:20:25 AM: ​
6:20:25 AM: Error location
6:20:25 AM: In Build command from Netlify app:
6:20:25 AM: CI=npm run build
6:20:25 AM: ​
6:20:25 AM: Resolved config
6:20:25 AM: build:
6:20:25 AM: command: CI=npm run build
6:20:25 AM: commandOrigin: ui
6:20:25 AM: publish: /opt/build/repo/build
6:20:25 AM: Caching artifacts

CI= npm run build (check the spaces) @kennymanman :+1:

hey guys i tried everything and still cant build the app

9:25:22 AM: v12.18.0 is already installed.
9:25:23 AM: Now using node v12.18.0 (npm v6.14.4)
9:25:23 AM: Started restoring cached build plugins
9:25:23 AM: Finished restoring cached build plugins
9:25:23 AM: Attempting ruby version 2.7.1, read from environment
9:25:24 AM: Using ruby version 2.7.1
9:25:24 AM: Using PHP version 5.6
9:25:24 AM: 5.2 is already installed.
9:25:24 AM: Using Swift version 5.2
9:25:24 AM: Started restoring cached node modules
9:25:24 AM: Finished restoring cached node modules
9:25:25 AM: Installing NPM modules using NPM version 6.14.4
9:25:29 AM: > nodemon@2.0.2 postinstall /opt/build/repo/node_modules/nodemon
9:25:29 AM: > node bin/postinstall || exit 0
9:25:29 AM: Love nodemon? You can now support the project via the open collective:
9:25:29 AM: > Contribute to nodemon - Open Collective
9:25:29 AM: npm WARN chatcord@1.0.0 No repository field.
9:25:29 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/fsevents):
9:25:29 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
9:25:29 AM: added 198 packages from 107 contributors and audited 199 packages in 3.474s
9:25:29 AM: 1 package is looking for funding
9:25:29 AM: run npm fund for details
9:25:29 AM: found 1 high severity vulnerability
9:25:29 AM: run npm audit fix to fix them, or npm audit for details
9:25:29 AM: NPM modules installed
9:25:29 AM: Started restoring cached go cache
9:25:29 AM: Finished restoring cached go cache
9:25:29 AM: go version go1.14.4 linux/amd64
9:25:29 AM: go version go1.14.4 linux/amd64
9:25:29 AM: Installing missing commands
9:25:29 AM: Verify run directory
9:25:30 AM: ​
9:25:30 AM: ┌─────────────────────────────┐
9:25:30 AM: │ Netlify Build │
9:25:30 AM: └─────────────────────────────┘
9:25:30 AM: ​
9:25:30 AM: ❯ Version
9:25:30 AM: @netlify/build 3.0.1
9:25:30 AM: ​
9:25:30 AM: ❯ Flags
9:25:30 AM: deployId: 5f28103cff928d8cb3cb913d
9:25:30 AM: mode: buildbot
9:25:30 AM: ​
9:25:30 AM: ❯ Current directory
9:25:30 AM: /opt/build/repo
9:25:30 AM: ​
9:25:30 AM: ❯ Config file
9:25:30 AM: No config file was defined: using default values.
9:25:30 AM: ​
9:25:30 AM: ❯ Context
9:25:30 AM: production
9:25:30 AM: ​
9:25:30 AM: ┌───────────────────────────────────┐
9:25:30 AM: │ 1. Build command from Netlify app │
9:25:30 AM: └───────────────────────────────────┘
9:25:30 AM: ​
9:25:30 AM: $ CI= npm run build
9:25:31 AM: npm ERR! missing script: build
9:25:31 AM: npm ERR! A complete log of this run can be found in:
9:25:31 AM: npm ERR! /opt/buildhome/.npm/_logs/2020-08-03T13_25_31_192Z-debug.log
9:25:31 AM: ​
9:25:31 AM: ┌─────────────────────────────┐
9:25:31 AM: │ “build.command” failed │
9:25:31 AM: └─────────────────────────────┘
9:25:31 AM: ​
9:25:31 AM: Error message
9:25:31 AM: Command failed with exit code 1: CI= npm run build
9:25:31 AM: ​
9:25:31 AM: Error location
9:25:31 AM: In Build command from Netlify app:
9:25:31 AM: CI= npm run build
9:25:31 AM: ​
9:25:31 AM: Resolved config
9:25:31 AM: build:
9:25:31 AM: command: CI= npm run build
9:25:31 AM: commandOrigin: ui
9:25:31 AM: environment:
9:25:31 AM: - CI
9:25:31 AM: publish: /opt/build/repo/public
9:25:31 AM: Caching artifacts
9:25:31 AM: Started saving node modules
9:25:31 AM: Finished saving node modules
9:25:31 AM: Started saving build plugins
9:25:31 AM: Finished saving build plugins
9:25:31 AM: Started saving pip cache
9:25:31 AM: Finished saving pip cache
9:25:31 AM: Started saving emacs cask dependencies
9:25:31 AM: Finished saving emacs cask dependencies
9:25:31 AM: Started saving maven dependencies
9:25:31 AM: Finished saving maven dependencies
9:25:31 AM: Started saving boot dependencies
9:25:31 AM: Finished saving boot dependencies
9:25:31 AM: Started saving go dependencies
9:25:31 AM: Finished saving go dependencies
9:25:34 AM: Error running command: Build script returned non-zero exit code: 1
9:25:34 AM: Failing build: Failed to build site
9:25:34 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 1
9:25:34 AM: Finished processing build request in 15.866999081s

1 Like

this code here is the problem - we cannot run the command you are telling us to for some reason. Does this code work locally?

i just spent 4 hours as well felt like i was going to have a heart attack…i was so frustrated… then I came across CI= npm run build THAT FIXED IT in Build Settings -> Build command: CI= npm run build… I’m just happy it works!

1 Like

Hey, i tried the CI= npm run build but still doesn’t work.

hey there, can you post a screenshot of your build settings and also the content of your package.json please?

Hello kindly help I used the CI= npm run build. Am still getting this error I have also attached a screenshot of my json file.
1:13:52 PM: Build ready to start
1:13:54 PM: build-image version: 09c2cdcdf242cf2f57c9ee0fcad9d298fad9ad41
1:13:54 PM: build-image tag: v3.5.0
1:13:54 PM: buildbot version: daad1c7f6f985f432faa0e1d50982ae7149f9e0a
1:13:54 PM: Fetching cached dependencies
1:13:54 PM: Failed to fetch cache, continuing with build
1:13:54 PM: Starting to prepare the repo for build
1:13:55 PM: No cached dependencies found. Cloning fresh repo
1:13:55 PM: git clone https://github.com/ivy-ajanga/MyPortfolio
1:13:56 PM: Preparing Git Reference refs/heads/main
1:13:58 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: ‘build’ versus ‘build/’ in the Netlify UI
1:13:58 PM: Starting build script
1:13:58 PM: Installing dependencies
1:13:58 PM: Python version set to 2.7
1:14:00 PM: v12.18.0 is already installed.
1:14:00 PM: Now using node v12.18.0 (npm v6.14.4)
1:14:01 PM: Started restoring cached build plugins
1:14:01 PM: Finished restoring cached build plugins
1:14:01 PM: Attempting ruby version 2.7.1, read from environment
1:14:02 PM: Using ruby version 2.7.1
1:14:03 PM: Using PHP version 5.6
1:14:03 PM: Started restoring cached node modules
1:14:03 PM: Finished restoring cached node modules
1:14:03 PM: Installing NPM modules using NPM version 6.14.4
1:14:06 PM: npm WARN MyPortfolio@1.0.0 No repository field.
1:14:06 PM: up to date in 2.646s
1:14:06 PM: found 0 vulnerabilities
1:14:06 PM: NPM modules installed
1:14:07 PM: Started restoring cached go cache
1:14:07 PM: Finished restoring cached go cache
1:14:07 PM: go version go1.14.4 linux/amd64
1:14:07 PM: go version go1.14.4 linux/amd64
1:14:07 PM: Installing missing commands
1:14:07 PM: Verify run directory
1:14:09 PM: ​
1:14:09 PM: ────────────────────────────────────────────────────────────────
1:14:09 PM: Netlify Build
1:14:09 PM: ────────────────────────────────────────────────────────────────
1:14:09 PM: ​
1:14:09 PM: ❯ Version
1:14:09 PM: @netlify/build 5.5.2
1:14:09 PM: ​
1:14:09 PM: ❯ Flags
1:14:09 PM: deployId: 5fc8ba6057cfa0ebb9716e6b
1:14:09 PM: mode: buildbot
1:14:09 PM: ​
1:14:09 PM: ❯ Current directory
1:14:09 PM: /opt/build/repo
1:14:09 PM: ​
1:14:09 PM: ❯ Config file
1:14:09 PM: No config file was defined: using default values.
1:14:09 PM: ​
1:14:09 PM: ❯ Context
1:14:09 PM: production
1:14:09 PM: ​
1:14:09 PM: ────────────────────────────────────────────────────────────────
1:14:09 PM: 1. Build command from Netlify app
1:14:09 PM: ────────────────────────────────────────────────────────────────
1:14:09 PM: ​
1:14:09 PM: $ CI= npm run build
1:14:09 PM: npm ERR! missing script: build
1:14:09 PM: npm ERR! A complete log of this run can be found in:
1:14:09 PM: npm ERR! /opt/buildhome/.npm/_logs/2020-12-03T10_14_09_428Z-debug.log
1:14:09 PM: ​
1:14:09 PM: ────────────────────────────────────────────────────────────────
1:14:09 PM: “build.command” failed
1:14:09 PM: ────────────────────────────────────────────────────────────────
1:14:09 PM: ​
1:14:09 PM: Error message
1:14:09 PM: Command failed with exit code 1: CI= npm run build
1:14:09 PM: ​
1:14:09 PM: Error location
1:14:09 PM: In Build command from Netlify app:
1:14:09 PM: CI= npm run build
1:14:09 PM: ​
1:14:09 PM: Resolved config
1:14:09 PM: build:
1:14:09 PM: command: CI= npm run build
1:14:09 PM: commandOrigin: ui
1:14:09 PM: publish: /opt/build/repo/build
1:14:09 PM: Caching artifacts
1:14:09 PM: Started saving node modules
1:14:09 PM: Finished saving node modules
1:14:09 PM: Started saving build plugins
1:14:09 PM: Finished saving build plugins
1:14:09 PM: Started saving pip cache
1:14:09 PM: Finished saving pip cache
1:14:09 PM: Started saving emacs cask dependencies
1:14:09 PM: Finished saving emacs cask dependencies
1:14:09 PM: Started saving maven dependencies
1:14:09 PM: Finished saving maven dependencies
1:14:09 PM: Started saving boot dependencies
1:14:09 PM: Finished saving boot dependencies
1:14:09 PM: Started saving go dependencies
1:14:09 PM: Finished saving go dependencies
1:14:12 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:14:12 PM: Failing build: Failed to build site
1:14:12 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
1:14:12 PM: Finished processing build request in 17.979369755s

Hello kindly help I used the CI= npm run build. Am still getting this error I have also attached a screenshot of my json file.
1:13:52 PM: Build ready to start
1:13:54 PM: build-image version: 09c2cdcdf242cf2f57c9ee0fcad9d298fad9ad41
1:13:54 PM: build-image tag: v3.5.0
1:13:54 PM: buildbot version: daad1c7f6f985f432faa0e1d50982ae7149f9e0a
1:13:54 PM: Fetching cached dependencies
1:13:54 PM: Failed to fetch cache, continuing with build
1:13:54 PM: Starting to prepare the repo for build
1:13:55 PM: No cached dependencies found. Cloning fresh repo
1:13:55 PM: git clone https://github.com/ivy-ajanga/MyPortfolio
1:13:56 PM: Preparing Git Reference refs/heads/main
1:13:58 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: ‘build’ versus ‘build/’ in the Netlify UI
1:13:58 PM: Starting build script
1:13:58 PM: Installing dependencies
1:13:58 PM: Python version set to 2.7
1:14:00 PM: v12.18.0 is already installed.
1:14:00 PM: Now using node v12.18.0 (npm v6.14.4)
1:14:01 PM: Started restoring cached build plugins
1:14:01 PM: Finished restoring cached build plugins
1:14:01 PM: Attempting ruby version 2.7.1, read from environment
1:14:02 PM: Using ruby version 2.7.1
1:14:03 PM: Using PHP version 5.6
1:14:03 PM: Started restoring cached node modules
1:14:03 PM: Finished restoring cached node modules
1:14:03 PM: Installing NPM modules using NPM version 6.14.4
1:14:06 PM: npm WARN MyPortfolio@1.0.0 No repository field.
1:14:06 PM: up to date in 2.646s
1:14:06 PM: found 0 vulnerabilities
1:14:06 PM: NPM modules installed
1:14:07 PM: Started restoring cached go cache
1:14:07 PM: Finished restoring cached go cache
1:14:07 PM: go version go1.14.4 linux/amd64
1:14:07 PM: go version go1.14.4 linux/amd64
1:14:07 PM: Installing missing commands
1:14:07 PM: Verify run directory
1:14:09 PM: ​
1:14:09 PM: ────────────────────────────────────────────────────────────────
1:14:09 PM: Netlify Build
1:14:09 PM: ────────────────────────────────────────────────────────────────
1:14:09 PM: ​
1:14:09 PM: ❯ Version
1:14:09 PM: @netlify/build 5.5.2
1:14:09 PM: ​
1:14:09 PM: ❯ Flags
1:14:09 PM: deployId: 5fc8ba6057cfa0ebb9716e6b
1:14:09 PM: mode: buildbot
1:14:09 PM: ​
1:14:09 PM: ❯ Current directory
1:14:09 PM: /opt/build/repo
1:14:09 PM: ​
1:14:09 PM: ❯ Config file
1:14:09 PM: No config file was defined: using default values.
1:14:09 PM: ​
1:14:09 PM: ❯ Context
1:14:09 PM: production
1:14:09 PM: ​
1:14:09 PM: ────────────────────────────────────────────────────────────────
1:14:09 PM: 1. Build command from Netlify app
1:14:09 PM: ────────────────────────────────────────────────────────────────
1:14:09 PM: ​
1:14:09 PM: $ CI= npm run build
1:14:09 PM: npm ERR! missing script: build
1:14:09 PM: npm ERR! A complete log of this run can be found in:
1:14:09 PM: npm ERR! /opt/buildhome/.npm/_logs/2020-12-03T10_14_09_428Z-debug.log
1:14:09 PM: ​
1:14:09 PM: ────────────────────────────────────────────────────────────────
1:14:09 PM: “build.command” failed
1:14:09 PM: ────────────────────────────────────────────────────────────────
1:14:09 PM: ​
1:14:09 PM: Error message
1:14:09 PM: Command failed with exit code 1: CI= npm run build
1:14:09 PM: ​
1:14:09 PM: Error location
1:14:09 PM: In Build command from Netlify app:
1:14:09 PM: CI= npm run build
1:14:09 PM: ​
1:14:09 PM: Resolved config
1:14:09 PM: build:
1:14:09 PM: command: CI= npm run build
1:14:09 PM: commandOrigin: ui
1:14:09 PM: publish: /opt/build/repo/build
1:14:09 PM: Caching artifacts
1:14:09 PM: Started saving node modules
1:14:09 PM: Finished saving node modules
1:14:09 PM: Started saving build plugins
1:14:09 PM: Finished saving build plugins
1:14:09 PM: Started saving pip cache
1:14:09 PM: Finished saving pip cache
1:14:09 PM: Started saving emacs cask dependencies
1:14:09 PM: Finished saving emacs cask dependencies
1:14:09 PM: Started saving maven dependencies
1:14:09 PM: Finished saving maven dependencies
1:14:09 PM: Started saving boot dependencies
1:14:09 PM: Finished saving boot dependencies
1:14:09 PM: Started saving go dependencies
1:14:09 PM: Finished saving go dependencies
1:14:12 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:14:12 PM: Failing build: Failed to build site
1:14:12 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
1:14:12 PM: Finished processing build request in 17.979369755s

Hey @IvyAjanga,
So so sorry for the long delay here! I was able to find your site based on your deploy log, and I took a look at your settings in the site dashboard here: Netlify App

It looks like you have the correct build command there. From there, our buildbots run the command listed (CI= npm run build), which basically says “run whatever is listed as the “build” script in the package.json”, but then get snagged by your package.json, which does not have a build script:
https://github.com/ivy-ajanga/MyPortfolio/blob/main/package.json#L9

You have “test” but you will need a line that says “build”, so:

  "scripts": {
    "build": "..." <--- you need something in here
    "test": "echo \"Error: no test specified\" && exit 1"
  },

I couldn’t tell what framework you’re using to build, but the framework docs should tell you what that command needs to be. Let us know if there are any other questions and we’ll be happy to help!

Thank you! This was driving me crazy! :pray:

13 posts were split to a new topic: Jekyll site won’t build: Error: No such file or directory @ rb_sysopen