Failed during stage 'building site': Build script returned non-zero exit code: 2 - silver-swan-97c645

Netlify site name: silver-swan-97c645

Build Log:

5:12:49 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
5:12:45 PM: Netlify Build
5:12:45 PM: ────────────────────────────────────────────────────────────────
5:12:45 PM: ​
5:12:45 PM: ❯ Version
5:12:45 PM: @netlify/build 29.12.1
5:12:45 PM: ​
5:12:45 PM: ❯ Flags
5:12:45 PM: baseRelDir: true
5:12:45 PM: buildId: 649b0a645170cd0afec38fc1
5:12:45 PM: deployId: 649b0a645170cd0afec38fc3
5:12:45 PM: tracing:
5:12:45 PM: enabled: ‘false’
5:12:45 PM: host:
5:12:45 PM: parentSpanId: 58ce790e47fd89e1
5:12:45 PM: traceFlags: ‘01’
5:12:45 PM: traceId: 08ec24069947b8ed0d3b99340dec3b88
5:12:45 PM: ​
5:12:45 PM: ❯ Current directory
5:12:45 PM: /opt/build/repo/my-app
5:12:45 PM: ​
5:12:45 PM: ❯ Config file
5:12:45 PM: No config file was defined: using default values.
5:12:45 PM: ​
5:12:45 PM: ❯ Context
5:12:45 PM: production
5:12:45 PM: ​
5:12:45 PM: Build command from Netlify app
5:12:45 PM: ────────────────────────────────────────────────────────────────
5:12:45 PM: ​
5:12:45 PM: $ npm run build
5:12:46 PM: > my-app@0.1.0 build
5:12:46 PM: > react-scripts build
5:12:47 PM: Creating an optimized production build…
5:12:47 PM: Browserslist: caniuse-lite is outdated. Please run:
5:12:47 PM: npx update-browserslist-db@latest
5:12:47 PM: Why you should do it regularly: GitHub - browserslist/update-db: CLI tool to update caniuse-lite to refresh target browsers from Browserslist config
5:12:48 PM: Failed to compile.
5:12:48 PM:
5:12:48 PM: Module not found: Error: Can’t resolve ‘…/images/gallery/1.jpg’ in ‘/opt/build/repo/my-app/src/components’
5:12:48 PM: ​
5:12:48 PM: build.command failed
5:12:48 PM: ────────────────────────────────────────────────────────────────
5:12:48 PM: ​
5:12:48 PM: Error message
5:12:48 PM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
5:12:48 PM: ​
5:12:48 PM: Error location
5:12:48 PM: In Build command from Netlify app:
5:12:48 PM: npm run build
5:12:48 PM: ​
5:12:48 PM: Resolved config
5:12:48 PM: build:
5:12:48 PM: base: /opt/build/repo/my-app
5:12:48 PM: command: npm run build
5:12:48 PM: commandOrigin: ui
5:12:48 PM: publish: /opt/build/repo/my-app/build
5:12:48 PM: publishOrigin: ui
5:12:48 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:12:49 PM: Failing build: Failed to build site
5:12:49 PM: Finished processing build request in 27.631s

Building Settings:


Appreciate your help, thanks! :pray:

@melzopla Your issue is case sensitivity.

For example you import 1.jpg

But that file, and many others, have an extension of .JPG

Either rename the files so they’re lowercase to match the import, or change the import to actually be the name of the file.

In general I’d suggest just using lowercase for your own sanity.

hi @nathanmartin - thank you for the tip. I’ve amended all of the file extensions to lower case. However, the issue is still occurring. The website loads correctly on my local server without issue but there seems to be something blocking the netlify build. Do you know what else it could be?

@melzopla When I changed the filenames on my local system it proceed to the next issue, which was another filename, there’s no guarantee there aren’t other problems.

I’ll take a look.

@melzopla Running your build locally I can see that it throws a bunch of warnings:

I can also see from your original build log that you have your Build command set to:
npm run build

There is a build configuration variable of CI which defaults to true, which causes warnings to be treated as errors and cause the build to fail.

You can read about it here:

The easiest way to override it and ensure it is false will be to change your Build command to CI= npm run build

Or you could fix the warnings of course, it’s ultimately up to you.

@nathanmartin - I changed the alt text against the photos as it looks like react doesn’t like the word “photo” being used in the alt which I did not know. Removing “photo” from the alt appears to have resolved those errors and now the website is publishing correctly! Thanks SO much for your help :grin:

that’s awesome to hear! great debugging. (: