Build script returned non-zero exit code: 2; JSON file import issue?

I’m guessing this issue has something to do with the way the JSON files are being imported?

App has built fine previously. I have JSON objects that were previously in a .js file. Now they are direct imports from JSON files. Build failed after making this change. I am able to build and deploy the app locally with no problem. Do I need to move these files to a different directory?

This is a React app built with vite.

Deploy URL: https://exquisite-elf-d2dceb.netlify.app/

Context: production
Deployment Type: deploy with git
Last Broken Deploy URL: https://app.netlify.com/sites/exquisite-elf-d2dceb/deploys/64226921f07c92029eac4860
Last Successful Deploy URL: https://app.netlify.com/sites/exquisite-elf-d2dceb/deploys/641e5a7eb568c600081b7b5e

9:12:24 PM: build-image version: 5e2052dbf11f1636a7bac1839aff8991d186d620 (focal)
9:12:24 PM: buildbot version: 5e2052dbf11f1636a7bac1839aff8991d186d620
9:12:24 PM: Building without cache
9:12:24 PM: Starting to prepare the repo for build
9:12:24 PM: No cached dependencies found. Cloning fresh repo
9:12:24 PM: git clone --filter=blob:none GitHub - josephrmartinez/empathyAI
9:12:24 PM: Preparing Git Reference refs/heads/main
9:12:24 PM: Parsing package.json dependencies
9:12:26 PM: Starting to install dependencies
9:12:26 PM: Attempting Ruby version 2.7.2, read from environment
9:12:27 PM: Using Ruby version 2.7.2
9:12:28 PM: v16.19.1 is already installed.
9:12:28 PM: Now using node v16.19.1 (npm v8.19.3)
9:12:28 PM: Enabling Node.js Corepack
9:12:28 PM: Started restoring cached build plugins
9:12:28 PM: Finished restoring cached build plugins
9:12:28 PM: Started restoring cached corepack dependencies
9:12:28 PM: Finished restoring cached corepack dependencies
9:12:28 PM: No npm workspaces detected
9:12:28 PM: Started restoring cached node modules
9:12:28 PM: Finished restoring cached node modules
9:12:28 PM: Installing npm packages using npm version 8.19.3
9:12:30 PM: npm WARN deprecated source-map-resolve@0.6.0: See GitHub - lydell/source-map-resolve: [DEPRECATED] Resolve the source map and/or sources for a generated file.
9:12:33 PM: added 308 packages, and audited 309 packages in 4s
9:12:33 PM: 41 packages are looking for funding
9:12:33 PM: run npm fund for details
9:12:33 PM: found 0 vulnerabilities
9:12:33 PM: npm packages installed
9:12:33 PM: Python version set to 3.8
9:12:34 PM: Started restoring cached go cache
9:12:34 PM: Finished restoring cached go cache
9:12:34 PM: Installing Go version 1.19.5 (requested 1.19.5)
9:12:40 PM: go version go1.19.5 linux/amd64
9:12:41 PM: Using PHP version 8.0
9:12:41 PM: Install dependencies script success
9:12:41 PM: Starting build script
9:12:41 PM: Using stage install dependencies
9:12:41 PM: Detected 1 framework(s)
9:12:41 PM: “vite” at version “4.1.4”
9:12:41 PM: Section completed: initializing
9:12:42 PM: ​
9:12:42 PM: Netlify Build
9:12:42 PM: ────────────────────────────────────────────────────────────────
9:12:42 PM: ​
9:12:42 PM: ❯ Version
9:12:42 PM: @netlify/build 29.7.1
9:12:42 PM: ​
9:12:42 PM: ❯ Flags
9:12:42 PM: baseRelDir: true
9:12:42 PM: buildId: 64226921f07c92029eac485e
9:12:42 PM: deployId: 64226921f07c92029eac4860
9:12:42 PM: ​
9:12:42 PM: ❯ Current directory
9:12:42 PM: /opt/build/repo
9:12:42 PM: ​
9:12:42 PM: ❯ Config file
9:12:42 PM: No config file was defined: using default values.
9:12:42 PM: ​
9:12:42 PM: ❯ Context
9:12:42 PM: production
9:12:42 PM: ​
9:12:42 PM: 1. Build command from Netlify app
9:12:42 PM: ────────────────────────────────────────────────────────────────
9:12:42 PM: ​
9:12:42 PM: $ npm run build
9:12:43 PM: > selfempathyapp@0.0.0 build
9:12:43 PM: > vite build
9:12:43 PM: vite v4.1.4 building for production…
9:12:43 PM: transforming…
9:12:43 PM: ✓ 29 modules transformed.
9:12:43 PM: Could not resolve “./assets/feelings.json” from “src/App.jsx”
9:12:43 PM: file: /opt/build/repo/src/App.jsx
9:12:43 PM: error during build:
9:12:43 PM: RollupError: Could not resolve “./assets/feelings.json” from “src/App.jsx”
9:12:43 PM: at error (file:///opt/build/repo/node_modules/rollup/dist/es/shared/node-entry.js:2105:30)
9:12:43 PM: at ModuleLoader.handleInvalidResolvedId (file:///opt/build/repo/node_modules/rollup/dist/es/shared/node-entry.js:23630:24)
9:12:43 PM: at file:///opt/build/repo/node_modules/rollup/dist/es/shared/node-entry.js:23592:26
9:12:43 PM: ​
9:12:43 PM: “build.command” failed
9:12:43 PM: ────────────────────────────────────────────────────────────────
9:12:43 PM: ​
9:12:43 PM: Error message
9:12:43 PM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
9:12:43 PM: ​
9:12:43 PM: Error location
9:12:43 PM: In Build command from Netlify app:
9:12:43 PM: npm run build
9:12:43 PM: ​
9:12:44 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)
9:12:43 PM: Resolved config
9:12:43 PM: build:
9:12:43 PM: command: npm run build
9:12:43 PM: commandOrigin: ui
9:12:43 PM: publish: /opt/build/repo/dist
9:12:43 PM: publishOrigin: ui
9:12:43 PM: redirects:
9:12:44 PM: - from: /* status: 200 to: /index.htmlCaching artifacts
9:12:44 PM: Started saving node modules
9:12:44 PM: Finished saving node modules
9:12:44 PM: Started saving build plugins
9:12:44 PM: Finished saving build plugins
9:12:44 PM: Started saving corepack cache
9:12:44 PM: Finished saving corepack cache
9:12:44 PM: Started saving pip cache
9:12:44 PM: Finished saving pip cache
9:12:44 PM: Started saving emacs cask dependencies
9:12:44 PM: Finished saving emacs cask dependencies
9:12:44 PM: Started saving maven dependencies
9:12:44 PM: Finished saving maven dependencies
9:12:44 PM: Started saving boot dependencies
9:12:44 PM: Finished saving boot dependencies
9:12:44 PM: Started saving rust rustup cache
9:12:44 PM: Finished saving rust rustup cache
9:12:44 PM: Started saving go dependencies
9:12:44 PM: Finished saving go dependencies
9:12:44 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:12:44 PM: Failing build: Failed to build site
9:12:45 PM: Finished processing build request in 20.948s

Build settings

Runtime
Not set

Base directory
Not set

Build command
npm run build

Publish directory
dist

Deploy log visibility
Logs are public

Build status
Active

This is to do with case sensitivity as outlined in

The file is feelings.JSON. You can either rename the file to feelings.json or change the import to feelings.JSON.

The same is applicable to complaints.JSON.

Brilliant. Thank you! Very helpful. And in case anyone else has this same issue: Do read the linked doc. You WILL need to delete the file, commit, add it back, and recommit in order for this fix to work. Renaming the file alone will not work.

Hi @josephmdev thanks for confirming you found your solution!