Build Failed with exit code 2

I recently migrated to vite from CRA on my react app. After which all my builds are failing form unknown reasons. Please help in finding them.

npm run build on local is working

link: Netlify App

Deploy logs

2:13:22 AM: build-image version: d55944c047ef0aee2ac01971edde72cb2a50acfe (focal)
2:13:22 AM: build-image tag: v4.16.1
2:13:22 AM: buildbot version: 33f88475bcf3426608b49b7681d295235efb41f1
2:13:22 AM: Building without cache
2:13:22 AM: Starting to prepare the repo for build
2:13:22 AM: No cached dependencies found. Cloning fresh repo
2:13:22 AM: git clone GitHub - shelcia/Socialgram: Social Gram is a social media website that allows users to create and share content, similar to other popular platforms such as Twitter and Facebook. Users will be able to create posts, and share them with others. The platform also allows for users to react and engage with other user's content, such as by liking, commenting, or sharing.
2:13:24 AM: Preparing Git Reference refs/heads/master
2:13:24 AM: Parsing package.json dependencies
2:13:25 AM: Starting build script
2:13:25 AM: Installing dependencies
2:13:25 AM: Python version set to 2.7
2:13:26 AM: Downloading and installing node v12.18.0…
2:13:26 AM: Downloading https://nodejs.org/dist/v12.18.0/node-v12.18.0-linux-x64.tar.xz
2:13:26 AM: Computing checksum with sha256sum
2:13:26 AM: Checksums matched!
2:13:28 AM: Now using node v12.18.0 (npm v6.14.4)
2:13:28 AM: Started restoring cached build plugins
2:13:28 AM: Finished restoring cached build plugins
2:13:28 AM: Attempting ruby version 2.7.1, read from environment
2:13:29 AM: Required ruby-2.7.1 is not installed - installing.
2:13:29 AM: Searching for binary rubies, this might take some time.
2:13:29 AM: Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-2.7.1.tar.bz2
2:13:29 AM: Checking requirements for ubuntu.
2:13:29 AM: Requirements installation successful.
2:13:30 AM: ruby-2.7.1 - #configure
2:13:30 AM: ruby-2.7.1 - #download
2:13:30 AM: ruby-2.7.1 - #validate archive
2:13:35 AM: ruby-2.7.1 - #extract
2:13:37 AM: ruby-2.7.1 - #validate binary
2:13:38 AM: ruby-2.7.1 - #setup
2:13:38 AM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1@global
2:13:38 AM: ruby-2.7.1 - #importing gemset /opt/buildhome/.rvm/gemsets/global.gems…
2:13:39 AM: ruby-2.7.1 - #generating global wrappers…
2:13:39 AM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1
2:13:39 AM: ruby-2.7.1 - #importing gemsetfile /opt/buildhome/.rvm/gemsets/default.gems evaluated to empty gem list
2:13:39 AM: ruby-2.7.1 - #generating default wrappers…
2:13:39 AM: Using /opt/buildhome/.rvm/gems/ruby-2.7.1
2:13:40 AM: Using ruby version 2.7.1
2:13:40 AM: Using PHP version 8.0
2:13:40 AM: No npm workspaces detected
2:13:40 AM: Started restoring cached node modules
2:13:40 AM: Finished restoring cached node modules
2:13:40 AM: Installing NPM modules using NPM version 6.14.4
2:13:46 AM: npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I’ll try to do my best with it!
2:13:46 AM: > esbuild@0.16.10 postinstall /opt/build/repo/node_modules/esbuild
2:13:46 AM: > node install.js
2:13:46 AM: > styled-components@5.3.6 postinstall /opt/build/repo/node_modules/styled-components
2:13:46 AM: > node ./postinstall.js
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/android-arm@0.16.10 (node_modules/@esbuild/android-arm):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/android-arm@0.16.10: wanted {“os”:“android”,“arch”:“arm”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/android-x64@0.16.10 (node_modules/@esbuild/android-x64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/android-x64@0.16.10: wanted {“os”:“android”,“arch”:“x64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/android-arm64@0.16.10 (node_modules/@esbuild/android-arm64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/android-arm64@0.16.10: wanted {“os”:“android”,“arch”:“arm64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/darwin-arm64@0.16.10 (node_modules/@esbuild/darwin-arm64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/darwin-arm64@0.16.10: wanted {“os”:“darwin”,“arch”:“arm64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/darwin-x64@0.16.10 (node_modules/@esbuild/darwin-x64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/darwin-x64@0.16.10: wanted {“os”:“darwin”,“arch”:“x64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/freebsd-arm64@0.16.10 (node_modules/@esbuild/freebsd-arm64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/freebsd-arm64@0.16.10: wanted {“os”:“freebsd”,“arch”:“arm64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/freebsd-x64@0.16.10 (node_modules/@esbuild/freebsd-x64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/freebsd-x64@0.16.10: wanted {“os”:“freebsd”,“arch”:“x64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-arm@0.16.10 (node_modules/@esbuild/linux-arm):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-arm@0.16.10: wanted {“os”:“linux”,“arch”:“arm”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-arm64@0.16.10 (node_modules/@esbuild/linux-arm64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-arm64@0.16.10: wanted {“os”:“linux”,“arch”:“arm64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-loong64@0.16.10 (node_modules/@esbuild/linux-loong64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-loong64@0.16.10: wanted {“os”:“linux”,“arch”:“loong64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-mips64el@0.16.10 (node_modules/@esbuild/linux-mips64el):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-mips64el@0.16.10: wanted {“os”:“linux”,“arch”:“mips64el”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-ia32@0.16.10 (node_modules/@esbuild/linux-ia32):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-ia32@0.16.10: wanted {“os”:“linux”,“arch”:“ia32”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-ppc64@0.16.10 (node_modules/@esbuild/linux-ppc64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-ppc64@0.16.10: wanted {“os”:“linux”,“arch”:“ppc64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-riscv64@0.16.10 (node_modules/@esbuild/linux-riscv64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-riscv64@0.16.10: wanted {“os”:“linux”,“arch”:“riscv64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-s390x@0.16.10 (node_modules/@esbuild/linux-s390x):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-s390x@0.16.10: wanted {“os”:“linux”,“arch”:“s390x”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/netbsd-x64@0.16.10 (node_modules/@esbuild/netbsd-x64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/netbsd-x64@0.16.10: wanted {“os”:“netbsd”,“arch”:“x64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/openbsd-x64@0.16.10 (node_modules/@esbuild/openbsd-x64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/openbsd-x64@0.16.10: wanted {“os”:“openbsd”,“arch”:“x64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/win32-arm64@0.16.10 (node_modules/@esbuild/win32-arm64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/win32-arm64@0.16.10: wanted {“os”:“win32”,“arch”:“arm64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/sunos-x64@0.16.10 (node_modules/@esbuild/sunos-x64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/sunos-x64@0.16.10: wanted {“os”:“sunos”,“arch”:“x64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/win32-ia32@0.16.10 (node_modules/@esbuild/win32-ia32):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/win32-ia32@0.16.10: wanted {“os”:“win32”,“arch”:“ia32”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/win32-x64@0.16.10 (node_modules/@esbuild/win32-x64):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/win32-x64@0.16.10: wanted {“os”:“win32”,“arch”:“x64”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
2:13:46 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
2:13:46 AM: added 192 packages from 186 contributors and audited 215 packages in 5.679s
2:13:46 AM: 29 packages are looking for funding
2:13:46 AM: run npm fund for details
2:13:46 AM: found 0 vulnerabilities
2:13:46 AM: NPM modules installed
2:13:46 AM: Creating package sha
2:13:46 AM: Started restoring cached go cache
2:13:46 AM: Finished restoring cached go cache
2:13:47 AM: Installing Go version 1.14.4 (requested 1.14.4)
2:13:51 AM: unset GOOS;
2:13:51 AM: unset GOARCH;
2:13:51 AM: export GOROOT=‘/opt/buildhome/.gimme/versions/go1.14.4.linux.amd64’;
2:13:51 AM: export PATH=“/opt/buildhome/.gimme/versions/go1.14.4.linux.amd64/bin:${PATH}”;
2:13:51 AM: go version >&2;
2:13:51 AM: export GIMME_ENV=“/opt/buildhome/.gimme/env/go1.14.4.linux.amd64.env”
2:13:51 AM: go version go1.14.4 linux/amd64
2:13:51 AM: Detected 1 framework(s)
2:13:51 AM: “vite” at version “4.0.3”
2:13:51 AM: Installing missing commands
2:13:51 AM: Verify run directory
2:13:51 AM: Section completed: initializing
2:13:53 AM: ​
2:13:53 AM: Netlify Build
2:13:53 AM: ────────────────────────────────────────────────────────────────
2:13:53 AM: ​
2:13:53 AM: ❯ Version
2:13:53 AM: @netlify/build 29.2.1
2:13:53 AM: ​
2:13:53 AM: ❯ Flags
2:13:53 AM: baseRelDir: true
2:13:53 AM: buildId: 63a8b5e81e1ae50439e3155f
2:13:53 AM: deployId: 63a8b5e81e1ae50439e31561
2:13:53 AM: ​
2:13:53 AM: ❯ Current directory
2:13:53 AM: /opt/build/repo
2:13:53 AM: ​
2:13:53 AM: ❯ Config file
2:13:53 AM: No config file was defined: using default values.
2:13:53 AM: ​
2:13:53 AM: ❯ Context
2:13:53 AM: production
2:13:53 AM: ​
2:13:53 AM: 1. Build command from Netlify app
2:13:53 AM: ────────────────────────────────────────────────────────────────
2:13:53 AM: ​
2:13:53 AM: $ npm run build
2:13:53 AM: > socialgram@1.1.0 build /opt/build/repo
2:13:53 AM: > vite build
2:13:53 AM: (node:3377) ExperimentalWarning: The ESM module loader is experimental.
2:13:53 AM: file:///opt/build/repo/node_modules/vite/bin/vite.js:7
2:13:53 AM: await import(‘source-map-support’).then((r) => r.default.install())
2:13:53 AM: ^^^^^
2:13:53 AM: SyntaxError: Unexpected reserved word
2:13:53 AM: at Loader.moduleStrategy (internal/modules/esm/translators.js:81:18)
2:13:53 AM: at async link (internal/modules/esm/module_job.js:37:21)
2:13:53 AM: npm ERR! code ELIFECYCLE
2:13:53 AM: npm ERR! errno 1
2:13:53 AM: npm ERR! socialgram@1.1.0 build: vite build
2:13:53 AM: npm ERR! Exit status 1
2:13:53 AM: npm ERR!
2:13:53 AM: npm ERR! Failed at the socialgram@1.1.0 build script.
2:13:53 AM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2:13:53 AM: npm ERR! A complete log of this run can be found in:
2:13:53 AM: npm ERR! /opt/buildhome/.npm/_logs/2022-12-25T20_43_53_674Z-debug.log
2:13:53 AM: ​
2:13:53 AM: “build.command” failed
2:13:53 AM: ────────────────────────────────────────────────────────────────
2:13:53 AM: ​
2:13:53 AM: Error message
2:13:53 AM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
2:13:55 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
2:13:53 AM: ​
2:13:53 AM: Error location
2:13:53 AM: In Build command from Netlify app:
2:13:53 AM: npm run build
2:13:53 AM: ​
2:13:53 AM: Resolved config
2:13:53 AM: build:
2:13:53 AM: command: npm run build
2:13:53 AM: commandOrigin: ui
2:13:53 AM: environment:
2:13:53 AM: - REACT_APP_HEROKU_LINK
2:13:53 AM: publish: /opt/build/repo/dist
2:13:53 AM: publishOrigin: ui
2:13:54 AM: Caching artifacts
2:13:54 AM: Started saving node modules
2:13:54 AM: Finished saving node modules
2:13:54 AM: Started saving build plugins
2:13:54 AM: Finished saving build plugins
2:13:54 AM: Started saving pip cache
2:13:54 AM: Finished saving pip cache
2:13:54 AM: Started saving emacs cask dependencies
2:13:54 AM: Finished saving emacs cask dependencies
2:13:54 AM: Started saving maven dependencies
2:13:54 AM: Finished saving maven dependencies
2:13:54 AM: Started saving boot dependencies
2:13:54 AM: Finished saving boot dependencies
2:13:54 AM: Started saving rust rustup cache
2:13:54 AM: Finished saving rust rustup cache
2:13:54 AM: Started saving go dependencies
2:13:54 AM: Finished saving go dependencies
2:13:55 AM: Cached ruby version 2.7.1
2:13:55 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:13:55 AM: Failing build: Failed to build site
2:13:55 AM: Finished processing build request in 33.336476471s

2:13:53 AM: SyntaxError: Unexpected reserved word

this is where the error stuff is

But there is nothing like in code

seems to be in the vite src code (?)
try to clear cache and deploy :+1:

I’d suggest that this build probably behaves the same on your local machine, right? Our CI can’t work if your local doesn’t :slight_smile:

This is what I’d run through if I were struggling with a build:

For anyone else having a similar problem, my error had a hint note about the node version. Upgraded node to 16.7.0 using nvm it and it worked. My error below was
SyntaxError: Unexpected reserved word

Here’s my full output:

$npm install netlify-cli --g
npm does not support Node.js v14.5.0
You should probably upgrade to a newer version of node as we
can’t make any promises that npm will work with this version.
You can find the latest version at https://nodejs.org/
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: ‘netlify-cli@13.0.0’,
npm WARN EBADENGINE required: { node: ‘^14.16.0 || >=16.0.0’ },
npm WARN EBADENGINE current: { node: ‘v14.5.0’, npm: ‘8.18.0’ }
npm WARN EBADENGINE }
npm WARN deprecated source-map-url@0.4.1: See GitHub - lydell/source-map-url: [DEPRECATED] Tools for working with sourceMappingURL comments.
npm WARN deprecated urix@0.1.0: Please see GitHub - lydell/urix: [DEPRECATED] Makes Windows-style paths more unix and URI friendly.
npm WARN deprecated resolve-url@0.2.1: GitHub - lydell/resolve-url: [DEPRECATED] Like Node.js’ `path.resolve`/`url.resolve` for the browser.
npm WARN deprecated source-map-resolve@0.5.3: See GitHub - lydell/source-map-resolve: [DEPRECATED] Resolve the source map and/or sources for a generated file.
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm ERR! code 1
npm ERR! path /Users/user/.nvm/versions/node/v14.5.0/lib/node_modules/netlify-cli
npm ERR! command failed
npm ERR! command sh -c – node ./scripts/postinstall.mjs
npm ERR! file:///Users/user/.nvm/versions/node/v14.5.0/lib/node_modules/netlify-cli/scripts/postinstall.mjs:60
npm ERR! await postInstall()
npm ERR! ^^^^^
npm ERR!
npm ERR! SyntaxError: Unexpected reserved word
npm ERR! at Loader.moduleStrategy (internal/modules/esm/translators.js:122:18)
npm ERR! at async link (internal/modules/esm/module_job.js:42:21)

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/user/.npm/_logs/2023-02-28T20_59_36_663Z-debug-0.log

thank you for sharing your solution! This is definitely helpful for other users

1 Like