Home
Support Forums

Building script returned non zero exit code:2

In local machine it is working fine but when i deploy on netlify, it is not. What is the issue? Can someone guide? I have added _redirects file in public folder. Also CI= npm run build is set in environment variable

2:40:14 PM: Build ready to start
2:40:17 PM: build-image version: 73def8bb10593b9b818f44989a75ea508018ccb7 (focal)
2:40:17 PM: build-image tag: v4.5.2
2:40:17 PM: buildbot version: ff9e2433dccff2a568f42fdd27a8e92c84c8a325
2:40:17 PM: Fetching cached dependencies
2:40:17 PM: Failed to fetch cache, continuing with build
2:40:17 PM: Starting to prepare the repo for build
2:40:17 PM: No cached dependencies found. Cloning fresh repo
2:40:17 PM: git clone https://github.com/harshitbadollacodes/e-commerce
2:40:19 PM: Preparing Git Reference refs/heads/development
2:40:19 PM: Parsing package.json dependencies
2:40:20 PM: Starting build script
2:40:20 PM: Installing dependencies
2:40:20 PM: Python version set to 2.7
2:40:21 PM: v16.13.1 is already installed.
2:40:21 PM: Now using node v16.13.1 (npm v8.1.2)
2:40:22 PM: Started restoring cached build plugins
2:40:22 PM: Finished restoring cached build plugins
2:40:22 PM: Attempting ruby version 2.7.2, read from environment
2:40:23 PM: Using ruby version 2.7.2
2:40:24 PM: Using PHP version 8.0
2:40:24 PM: Started restoring cached node modules
2:40:24 PM: Finished restoring cached node modules
2:40:24 PM: Installing NPM modules using NPM version 8.1.2
2:40:41 PM: npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
2:40:41 PM: npm WARN deprecated har-validator@5.1.5: this library is no longer supported
2:40:42 PM: npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
2:40:45 PM: npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
2:40:45 PM: npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
2:40:48 PM: npm WARN deprecated rollup-plugin-babel@4.4.0: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-babel.
2:40:55 PM: npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
2:40:56 PM: npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
2:40:56 PM: npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
2:40:57 PM: npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
2:40:59 PM: npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
2:41:01 PM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
2:41:01 PM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
2:41:03 PM: npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
2:41:11 PM: npm WARN deprecated core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
2:41:14 PM: added 1991 packages, and audited 1992 packages in 50s
2:41:14 PM: 135 packages are looking for funding
2:41:14 PM:   run `npm fund` for details
2:41:14 PM: 114 vulnerabilities (2 low, 98 moderate, 12 high, 2 critical)
2:41:14 PM: To address issues that do not require attention, run:
2:41:14 PM:   npm audit fix
2:41:14 PM: To address all issues (including breaking changes), run:
2:41:14 PM:   npm audit fix --force
2:41:14 PM: Run `npm audit` for details.
2:41:14 PM: NPM modules installed
2:41:15 PM: Started restoring cached go cache
2:41:15 PM: Finished restoring cached go cache
2:41:15 PM: go version go1.16.5 linux/amd64
2:41:15 PM: go version go1.16.5 linux/amd64
2:41:15 PM: Installing missing commands
2:41:15 PM: Verify run directory
2:41:17 PM: ​
2:41:17 PM: ────────────────────────────────────────────────────────────────
2:41:17 PM:   Netlify Build                                                 
2:41:17 PM: ────────────────────────────────────────────────────────────────
2:41:17 PM: ​
2:41:17 PM: ❯ Version
2:41:17 PM:   @netlify/build 26.1.0
2:41:17 PM: ​
2:41:17 PM: ❯ Flags
2:41:17 PM:   baseRelDir: true
2:41:17 PM:   buildId: 61dbf7f6cefee06c413c2bba
2:41:17 PM:   deployId: 61dbf7f6cefee06c413c2bbc
2:41:17 PM: ​
2:41:17 PM: ❯ Current directory
2:41:17 PM:   /opt/build/repo
2:41:17 PM: ​
2:41:17 PM: ❯ Config file
2:41:17 PM:   No config file was defined: using default values.
2:41:17 PM: ​
2:41:17 PM: ❯ Context
2:41:17 PM:   production
2:41:17 PM: ​
2:41:17 PM: ────────────────────────────────────────────────────────────────
2:41:17 PM:   1. Build command from Netlify app                             
2:41:17 PM: ────────────────────────────────────────────────────────────────
2:41:17 PM: ​
2:41:17 PM: $ CI= npm run build
2:41:17 PM: > e-commerce@0.1.0 build
2:41:17 PM: > react-scripts build
2:41:19 PM: Creating an optimized production build...
2:41:20 PM: Browserslist: caniuse-lite is outdated. Please run:
2:41:20 PM: npx browserslist@latest --update-db
2:41:20 PM: Why you should do it regularly:
2:41:20 PM: https://github.com/browserslist/browserslist#browsers-data-updating
2:41:20 PM: Failed to compile.
2:41:20 PM: 
2:41:20 PM: ./src/index.js
2:41:20 PM: Cannot find file './context/ProductsContext' in './src'.
2:41:20 PM: ​
2:41:20 PM: ────────────────────────────────────────────────────────────────
2:41:20 PM:   "build.command" failed                                        
2:41:20 PM: ────────────────────────────────────────────────────────────────
2:41:20 PM: ​
2:41:20 PM:   Error message
2:41:20 PM:   Command failed with exit code 1: CI= npm run build
2:41:20 PM: ​
2:41:20 PM:   Error location
2:41:20 PM:   In Build command from Netlify app:
2:41:20 PM:   CI= npm run build
2:41:20 PM: ​
2:41:20 PM:   Resolved config
2:41:20 PM:   build:
2:41:20 PM:     command: CI= npm run build
2:41:20 PM:     commandOrigin: ui
2:41:20 PM:     environment:
2:41:20 PM:       - CI
2:41:20 PM:     publish: /opt/build/repo/build
2:41:20 PM:     publishOrigin: ui
2:41:21 PM: Caching artifacts
2:41:21 PM: Started saving node modules
2:41:21 PM: Finished saving node modules
2:41:21 PM: Started saving build plugins
2:41:21 PM: Finished saving build plugins
2:41:21 PM: Started saving pip cache
2:41:21 PM: Finished saving pip cache
2:41:21 PM: Started saving emacs cask dependencies
2:41:21 PM: Finished saving emacs cask dependencies
2:41:21 PM: Started saving maven dependencies
2:41:21 PM: Finished saving maven dependencies
2:41:21 PM: Started saving boot dependencies
2:41:21 PM: Finished saving boot dependencies
2:41:21 PM: Started saving rust rustup cache
2:41:21 PM: Finished saving rust rustup cache
2:41:21 PM: Started saving go dependencies
2:41:21 PM: Finished saving go dependencies
2:41:23 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:41:23 PM: Creating deploy upload records
2:41:23 PM: Failing build: Failed to build site
2:41:23 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
2:41:23 PM: Finished processing build request in 1m6.849247526s

Hi @harshitbadolla5

In GitHub context has an uppercase C so it is Context. The build system is case sensitive (unlike Windows and some macOS file systems.)

You will need to ensure all imports have matching case in the path and filename