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

Hello I am facing an issue while deployment

1:17:59 AM: build-image version: 006dca901dab83234b4881f914ac1a189ff41daa (focal)
1:17:59 AM: buildbot version: e8a1f877a96ee9d2b754bae26acb6bb322cba939
1:17:59 AM: Fetching cached dependencies
1:17:59 AM: Starting to download cache of 22.1MB
1:18:00 AM: Finished downloading cache in 244ms
1:18:00 AM: Starting to extract cache
1:18:00 AM: Finished extracting cache in 35ms
1:18:00 AM: Finished fetching cache in 324ms
1:18:00 AM: Starting to prepare the repo for build
1:18:00 AM: Preparing Git Reference refs/heads/main
1:18:01 AM: Custom build path detected. Proceeding with the specified path: β€˜dist’
1:18:01 AM: Custom publish path detected. Proceeding with the specified path: β€˜dist’
1:18:01 AM: manpath: warning: $PATH not set
1:18:02 AM: Starting to install dependencies
1:18:02 AM: Python version set to 3.8
1:18:02 AM: Attempting Ruby version 2.7.2, read from environment
1:18:03 AM: Using Ruby version 2.7.2
1:18:03 AM: Started restoring cached go cache
1:18:03 AM: Finished restoring cached go cache
1:18:05 AM: go version go1.19.13 linux/amd64
1:18:05 AM: Using PHP version 8.0
1:18:07 AM: v18.20.3 is already installed.
1:18:07 AM: Now using node v18.20.3 (npm v10.7.0)
1:18:07 AM: Enabling Node.js Corepack
1:18:07 AM: Started restoring cached build plugins
1:18:07 AM: Finished restoring cached build plugins
1:18:07 AM: Started restoring cached corepack dependencies
1:18:07 AM: Finished restoring cached corepack dependencies
1:18:07 AM: No npm workspaces detected
1:18:07 AM: Started restoring cached node modules
1:18:07 AM: Finished restoring cached node modules
1:18:08 AM: Installing npm packages using npm version 10.7.0
1:18:09 AM: added 100 packages, and audited 101 packages in 2s
1:18:09 AM: 10 packages are looking for funding
1:18:09 AM: run npm fund for details
1:18:09 AM: found 0 vulnerabilities
1:18:09 AM: npm packages installed
1:18:10 AM: Successfully installed dependencies
1:18:10 AM: Starting build script
1:18:11 AM: Detected 1 framework(s)
1:18:11 AM: β€œvite” at version β€œ5.2.8”
1:18:11 AM: Section completed: initializing
1:18:12 AM: ​
1:18:12 AM: Netlify Build
1:18:12 AM: ────────────────────────────────────────────────────────────────
1:18:12 AM: ​
1:18:12 AM: ❯ Version
1:18:12 AM: @netlify/build 29.50.5
1:18:12 AM: ​
1:18:12 AM: ❯ Flags
1:18:12 AM: baseRelDir: true
1:18:12 AM: buildId: 66899f65e16e5b0008b265d7
1:18:12 AM: deployId: 66899f65e16e5b0008b265d9
1:18:12 AM: ​
1:18:12 AM: ❯ Current directory
1:18:12 AM: /opt/build/repo/dist
1:18:12 AM: ​
1:18:12 AM: ❯ Config file
1:18:12 AM: No config file was defined: using default values.
1:18:12 AM: ​
1:18:12 AM: ❯ Context
1:18:12 AM: production
1:18:12 AM: ​
1:18:12 AM: ❯ Installing plugins
1:18:12 AM: - @netlify/plugin-lighthouse@6.0.0
1:18:27 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)
1:18:24 AM: ​
1:18:24 AM: ❯ Loading plugins
1:18:24 AM: - @netlify/plugin-lighthouse@6.0.0 from Netlify app
1:18:26 AM: ​
1:18:26 AM: Build command from Netlify app
1:18:26 AM: ────────────────────────────────────────────────────────────────
1:18:26 AM: ​
1:18:26 AM: $ npm run dev
1:18:26 AM: > retro-computer-website@1.0.0 dev
1:18:26 AM: > vite --no-open
1:18:26 AM: β–² [WARNING] Duplicate key β€œscripts” in object literal [duplicate-object-key]
1:18:26 AM: package.json:32:2:
1:18:26 AM: 32 β”‚ β€œscripts”: {
1:18:26 AM: β•΅ ~~~~~~~~~
1:18:26 AM: The original key β€œscripts” is here:
1:18:26 AM: package.json:14:2:
1:18:26 AM: 14 β”‚ β€œscripts”: {
1:18:26 AM: β•΅ ~~~~~~~~~
1:18:27 AM: VITE v5.2.8 ready in 404 ms
1:18:27 AM: ➜ Local: http://localhost:1234/
1:18:27 AM: (!) Could not auto-determine entry point from rollupOptions or html files and there are no explicit optimizeDeps.include patterns. Skipping dependency pre-bundling.
1:18:27 AM: node:internal/event_target:1062
1:18:27 AM: process.nextTick(() => { throw err; });
1:18:27 AM: ^
1:18:27 AM: Error: Failed to find a valid tsconfig.json: tsconfig.json at /opt/build/repo/dist is not a valid tsconfig
1:18:27 AM: at Object.configureServer (file:///opt/build/repo/dist/node_modules/vite-plugin-checker/dist/esm/checkers/typescript/main.js:38:15)
1:18:27 AM: at MessagePort. (file:///opt/build/repo/dist/node_modules/vite-plugin-checker/dist/esm/worker.js:57:26)
1:18:27 AM: at [nodejs.internal.kHybridDispatch] (node:internal/event_target:786:20)
1:18:27 AM: at exports.emitMessage (node:internal/per_context/messageport:23:28)
1:18:27 AM: Emitted β€˜error’ event on Worker instance at:
1:18:27 AM: at [kOnErrorMessage] (node:internal/worker:314:10)
1:18:27 AM: at [kOnMessage] (node:internal/worker:325:37)
1:18:27 AM: at MessagePort. (node:internal/worker:225:57)
1:18:27 AM: at [nodejs.internal.kHybridDispatch] (node:internal/event_target:786:20)
1:18:27 AM: at exports.emitMessage (node:internal/per_context/messageport:23:28)
1:18:27 AM: Node.js v18.20.3
1:18:27 AM: ​
1:18:27 AM: β€œbuild.command” failed
1:18:27 AM: ────────────────────────────────────────────────────────────────
1:18:27 AM: ​
1:18:27 AM: Error message
1:18:27 AM: Command failed with exit code 1: npm run dev (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
1:18:27 AM: ​
1:18:27 AM: Error location
1:18:27 AM: In Build command from Netlify app:
1:18:27 AM: npm run dev
1:18:27 AM: ​
1:18:27 AM: Resolved config
1:18:27 AM: build:
1:18:27 AM: base: /opt/build/repo/dist
1:18:27 AM: command: npm run dev
1:18:27 AM: commandOrigin: ui
1:18:27 AM: publish: /opt/build/repo/dist
1:18:27 AM: publishOrigin: default
1:18:27 AM: plugins:
1:18:27 AM: - inputs: {}
1:18:27 AM: origin: ui
1:18:27 AM: package: β€˜@netlify/plugin-lighthouse’
1:18:27 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:18:27 AM: Failing build: Failed to build site
1:18:28 AM: Finished processing build request in 28.361s

github repo: GitHub - aaaaryaannn/Portfolio

@aaaaryaannn You have a few issues.

You don’t want to run npm run dev
You can’t run and serve the development server on Netlify.

Normally you would want to run npm run build.
Except, checking what you have in your repository…

Your project only has files in a dist folder.
All of the files seem to be the output of a local build, (e.g. they’re not source files).

Except, these files normally wouldn’t be in your build output:

package-lock.json
package.json
vite.config.ts

With what you currently have in that repository, if you deleted the three files above, and then changed your Netlify Build command to just be blank, (e.g. don’t run anything), you’ll find it just deploys what you have and that it works.

1 Like

Thank you nathan for reverting back but when I delete those files and change command to npm run build, AI diagnosis says:
Diagnosis: The build is failing because the npm run build command is unable to find the package.json file in the /opt/build/repo/dist directory.

Solution: Make sure that the package.json file is present in the correct directory (/opt/build/repo/dist) before running the npm run build command. Check the build configuration to ensure the correct path to the package.json file is specified.

It looks like you figured out what I meant, but you wouldn’t run npm run build.
You would just leave the Build command completely blank, since you don’t need to run anything.

Note that, if repository contained your source code, you could run your build on Netlify.
I’ve only provided the details I did because your repository only contains your build output (not source).

1 Like

KUDOS TO NATHAN, YOU ARE GENIUS!!!

Thank you so much, it worked.

Also will help me with forms I did used <form id="nl-form" class="nl-form" netlify>

but all I get is blanks in responses

I’d imagine your form is just constructed poorly.

There’s no name for the various form inputs etc.

You should refer to the documentation:

https://docs.netlify.com/forms/setup/

1 Like

Thanks a lot it worked you’re awesome already