Getting error - Building script returned non zero exit code:2

Works on my local, but fails building every time on netlify. Please help

1:55:09 AM: build-image version: c88e1420630449f4a2fd995ed7cd2ef80eeab5f6 (focal)
1:55:09 AM: buildbot version: c88e1420630449f4a2fd995ed7cd2ef80eeab5f6
1:55:09 AM: Building without cache
1:55:09 AM: Starting to prepare the repo for build
1:55:09 AM: No cached dependencies found. Cloning fresh repo
1:55:09 AM: git clone --filter=blob:none https://github.com/justicenugo/CapstoneWebApp
1:55:10 AM: Preparing Git Reference refs/heads/main
1:55:17 AM: Starting to install dependencies
1:55:17 AM: Python version set to 3.8
1:55:17 AM: Attempting Ruby version 2.7.2, read from environment
1:55:17 AM: Using Ruby version 2.7.2
1:55:18 AM: Started restoring cached go cache
1:55:18 AM: Finished restoring cached go cache
1:55:19 AM: go version go1.19.13 linux/amd64
1:55:19 AM: Using PHP version 8.0
1:55:20 AM: v18.19.0 is already installed.
1:55:21 AM: Now using node v18.19.0 (npm v10.2.3)
1:55:21 AM: Enabling Node.js Corepack
1:55:21 AM: Started restoring cached build plugins
1:55:21 AM: Finished restoring cached build plugins
1:55:21 AM: Started restoring cached corepack dependencies
1:55:21 AM: Finished restoring cached corepack dependencies
1:55:21 AM: Started restoring cached yarn cache
1:55:21 AM: Finished restoring cached yarn cache
1:55:21 AM: No yarn workspaces detected
1:55:21 AM: Started restoring cached node modules
1:55:21 AM: Finished restoring cached node modules
1:55:21 AM: Installing npm packages using Yarn version 1.22.19
1:55:22 AM: yarn install v1.22.19
1:55:22 AM: warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
1:55:22 AM: [1/4] Resolving packages...
1:55:23 AM: [2/4] Fetching packages...
1:55:31 AM: [3/4] Linking dependencies...
1:55:34 AM: [4/4] Building fresh packages...
1:55:44 AM: success Saved lockfile.
1:55:44 AM: Done in 21.94s.
1:55:44 AM: npm packages installed using Yarn
1:55:44 AM: Successfully installed dependencies
1:55:44 AM: Starting build script
1:55:45 AM: Detected 1 framework(s)
1:55:45 AM: "vite" at version "4.5.0"
1:55:45 AM: Section completed: initializing
1:55:47 AM: ​
1:55:47 AM: Netlify Build                                                 
1:55:47 AM: ────────────────────────────────────────────────────────────────
1:55:47 AM: ​
1:55:47 AM: ❯ Version
1:55:47 AM:   @netlify/build 29.31.1
1:55:47 AM: ​
1:55:47 AM: ❯ Flags
1:55:47 AM:   baseRelDir: true
1:55:47 AM:   buildId: 658bd84130feee3542925a9f
1:55:47 AM:   deployId: 658bd84130feee3542925aa1
1:55:47 AM: ​
1:55:47 AM: ❯ Current directory
1:55:47 AM:   /opt/build/repo
1:55:47 AM: ​
1:55:47 AM: ❯ Config file
1:55:47 AM:   No config file was defined: using default values.
1:55:47 AM: ​
1:55:47 AM: ❯ Context
1:55:47 AM:   production
1:55:47 AM: ​
1:55:47 AM: Build command from Netlify app                                
1:55:47 AM: ────────────────────────────────────────────────────────────────
1:55:47 AM: ​
1:55:47 AM: $ npm run build
1:55:47 AM: > loomoneers-webapp-cap@0.0.0 build
1:55:47 AM: > vite build
1:55:48 AM: vite v4.5.0 building for production...
1:55:48 AM: transforming...
1:55:48 AM: ✓ 24 modules transformed.
1:55:48 AM: ✓ built in 580ms
1:55:48 AM: Could not resolve "../views/members/Alex.vue" from "src/router/router.js"
1:55:48 AM: file: /opt/build/repo/src/router/router.js
1:55:48 AM: error during build:
1:55:48 AM: RollupError: Could not resolve "../views/members/Alex.vue" from "src/router/router.js"
1:55:48 AM:     at error (file:///opt/build/repo/node_modules/rollup/dist/es/shared/node-entry.js:2287:30)
1:55:48 AM:     at ModuleLoader.handleInvalidResolvedId (file:///opt/build/repo/node_modules/rollup/dist/es/shared/node-entry.js:24860:24)
1:55:48 AM:     at file:///opt/build/repo/node_modules/rollup/dist/es/shared/node-entry.js:24822:26
1:55:49 AM: Failed during stage "building site": Build script returned non-zero exit code: 2
1:55:49 AM: ​
1:55:49 AM: "build.command" failed                                        
1:55:49 AM: ────────────────────────────────────────────────────────────────
1:55:49 AM: ​
1:55:49 AM:   Error message
1:55:49 AM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
1:55:49 AM: ​
1:55:49 AM:   Error location
1:55:49 AM:   In Build command from Netlify app:
1:55:49 AM:   npm run build
1:55:49 AM: ​
1:55:49 AM:   Resolved config
1:55:49 AM:   build:
1:55:49 AM:     command: npm run build
1:55:49 AM:     commandOrigin: ui
1:55:49 AM:     publish: /opt/build/repo/dist
1:55:49 AM:     publishOrigin: ui
1:55:49 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:55:49 AM: Failing build: Failed to build site
1:55:49 AM: Finished processing build request in 40.201s

[quote=“[Support Guide] Netlify app builds locally but fails on deploy (case sensitivity), post:1, topic:10754”]
ld see any problems related to t
[/quote]

i did this, renaming the file and pushing to github, but i am still getting the same error.

9:36:40 AM: Netlify Build                                                 
9:36:40 AM: ────────────────────────────────────────────────────────────────
9:36:40 AM: ​
9:36:40 AM: ❯ Version
9:36:40 AM:   @netlify/build 29.31.1
9:36:40 AM: ​
9:36:40 AM: ❯ Flags
9:36:40 AM:   baseRelDir: true
9:36:40 AM:   buildId: 658c44651673380007356470
9:36:40 AM:   deployId: 658c44651673380007356472
9:36:40 AM: ​
9:36:40 AM: ❯ Current directory
9:36:40 AM:   /opt/build/repo
9:36:40 AM: ​
9:36:40 AM: ❯ Config file
9:36:40 AM:   No config file was defined: using default values.
9:36:40 AM: ​
9:36:40 AM: ❯ Context
9:36:40 AM:   production
9:36:40 AM: ​
9:36:40 AM: Build command from Netlify app                                
9:36:40 AM: ────────────────────────────────────────────────────────────────
9:36:40 AM: ​
9:36:40 AM: $ npm run build
9:36:41 AM: > loomoneers-webapp-cap@0.0.0 build
9:36:41 AM: > vite build
9:36:41 AM: vite v4.5.0 building for production...
9:36:41 AM: transforming...
9:36:42 AM: Failed during stage "building site": Build script returned non-zero exit code: 2
9:36:42 AM: ✓ 24 modules transformed.
9:36:42 AM: ✓ built in 552ms
9:36:42 AM: Could not resolve "../views/members/alex.vue" from "src/router/router.js"
9:36:42 AM: file: /opt/build/repo/src/router/router.js
9:36:42 AM: error during build:
9:36:42 AM: RollupError: Could not resolve "../views/members/alex.vue" from "src/router/router.js"
9:36:42 AM:     at error (file:///opt/build/repo/node_modules/rollup/dist/es/shared/node-entry.js:2287:30)
9:36:42 AM:     at ModuleLoader.handleInvalidResolvedId (file:///opt/build/repo/node_modules/rollup/dist/es/shared/node-entry.js:24860:24)
9:36:42 AM:     at file:///opt/build/repo/node_modules/rollup/dist/es/shared/node-entry.js:24822:26
9:36:42 AM: ​
9:36:42 AM: "build.command" failed                                        
9:36:42 AM: ────────────────────────────────────────────────────────────────
9:36:42 AM: ​
9:36:42 AM:   Error message
9:36:42 AM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
9:36:42 AM: ​
9:36:42 AM:   Error location
9:36:42 AM:   In Build command from Netlify app:
9:36:42 AM:   npm run build
9:36:42 AM: ​
9:36:42 AM:   Resolved config
9:36:42 AM:   build:
9:36:42 AM:     command: npm run build
9:36:42 AM:     commandOrigin: ui
9:36:42 AM:     publish: /opt/build/repo/dist
9:36:42 AM:     publishOrigin: ui
9:36:42 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:36:42 AM: Failing build: Failed to build site
9:36:42 AM: Finished processing build request in 35.552s

Hi, @sonnofmann. Hrishikesh and I can see your repo because we work at Netlify. This means we can see Netlify internals so we know what repo this is for. No one else on the support forum (besides people working at Netlify) can see this.

Also, we cannot see private repos but this repo is public so we can inspect it on GitHub.

The issue here is that Linux filesystems are case-sensitive. You are referencing the file like this in the file src/router/router.js:

  • '../views/members/alex.vue'

However, the actual relative file path is this (with an upper-case “M” in “Members”):

  • src/views/Members/alex.vue

This means it must be referenced as:

  • '../views/Members/alex.vue'

It is still case-sensitivity. The case of the letters for entire path must match. You changed “Alex.vue” to “alex.vue” but “Members” is still mixed case.

thank you! i was able to fix it and get it deployed, to where it says Production: main@915286a published
I tried adding a netlify.toml file, however, i am still getting page not found when i click on Open production deploy

Hi, @sonnofmann. The “page not found” is happening because there is no index.html file in the base of the publish directory. You can confirm this by downloading the deploy.

As to why that file is missing, that I do not know. I know that it is missing but not why,

There is a favicon in that directory and requests to that URL are working. Please note, I’ve redacted the site name below as you haven’t shared it publicly yet (and I won’t unless you do so first):

$ curl --compressed -svo /dev/null --stderr - https://<REDACTED>.netlify.app/favicon.ico  | egrep '^(<|>)'
> GET /favicon.ico HTTP/2
> Host: <REDACTED>.netlify.app
> User-Agent: curl/8.4.0
> Accept: */*
> Accept-Encoding: deflate, gzip
>
< HTTP/2 200
< accept-ranges: bytes
< age: 0
< cache-control: public,max-age=0,must-revalidate
< cache-status: "Netlify Edge"; fwd=miss
< content-type: image/vnd.microsoft.icon
< date: Thu, 28 Dec 2023 22:40:02 GMT
< etag: "c07b73221f2d2030b0a90072d734fb9e-ssl"
< server: Netlify
< strict-transport-security: max-age=31536000; includeSubDomains; preload
< x-nf-request-id: 01HJS9BB7X2XDNYWN5R8JP1BAB
< content-length: 4286
<

So, the site is working. The issue now is that there is no HTML file for the base path (/). Again, the HTML file for the base path of / is called index.html for historical reasons.

If you add an index.html file, the 404s should stop happening for the base path URL as well. If there are other questions about this, please let us know.

i built my webapp using Vite and VueJS, could the structure be the reason why the index.html file is missing? because i have that file in my repo and can locally launch the webapp.

You should not be adding the index.html to your public folder:

Vite should add the correct file to dist automatically. If that’s not happening, this would be a Vite bug and it should be reported there.