← all conversations

Fix Netlify Build Error

2025-03-102 turns10,683 charsgpt-4o
netlifybuild-errortypescript

Summary

User is troubleshooting a Netlify build failure caused by a TypeScript unused variable error in MarkdownRenderer.tsx.

Messages

Diagnosis: The build failed with the error message "Failed during stage 'building site': Build script returned non-zero exit code: 2." Additionally, there is an error in the file "MarkdownRenderer.tsx" stating "'wrapper' is defined but never used" at line 107. Solution: To address the TypeScript error in "MarkdownRenderer.tsx" at line 107, you need to address the unused variable 'wrapper' as per the rule @typescript-eslint/no-unused-vars. To resolve the build failure "Build script returned non-zero exit code: 2", review your build command npm run build in the netlify.toml file. Ensure that the npm build script is correctly configured to handle any errors and that the build actually succeeds. Verify that your build script is correctly building your project without errors locally before deploying to Netlify. Need more help? Go to Ask Netlify Retry diagnostics Netlify uses AI to analyze and generate solutions to fix deploy failures. It may not always understand the full context or produce a reliable, accurate answer. To learn more, please refer to our docs. Did you find this helpful? Your feedback helps improve this feature. Initializing Complete 3:53:27 PM: build-image version: 9a361c83c6a43010ba0aa3ea38214accc0223b2c (focal) 3:53:27 PM: buildbot version: 9a4374dc9e2c1cbd2a152e441d69a3a6d7e12511 3:53:27 PM: Fetching cached dependencies 3:53:28 PM: Failed to fetch cache, continuing with build 3:53:28 PM: Starting to prepare the repo for build 3:53:28 PM: No cached dependencies found. Cloning fresh repo 3:53:28 PM: git clone --filter=blob:none https://github.com/kliewerdaniel/blog06 3:53:28 PM: Preparing Git Reference refs/heads/main 3:53:29 PM: Custom functions path detected. Proceeding with the specified path: 'netlify/functions' 3:53:30 PM: Starting to install dependencies 3:53:32 PM: mise python@3.13.2 install 3:53:32 PM: mise python@3.13.2 download cpython-3.13.2+20250212-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz 3:53:33 PM: mise python@3.13.2 extract cpython-3.13.2+20250212-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz 3:53:34 PM: mise python@3.13.2 python --version 3:53:34 PM: mise python@3.13.2 Python 3.13.2 3:53:34 PM: mise python@3.13.2 ✓ installed 3:53:34 PM: Python version set to 3.13 3:53:36 PM: Collecting pipenv 3:53:36 PM: Downloading pipenv-2024.4.1-py3-none-any.whl.metadata (17 kB) 3:53:36 PM: Collecting certifi (from pipenv) 3:53:36 PM: Downloading certifi-2025.1.31-py3-none-any.whl.metadata (2.5 kB) 3:53:36 PM: Collecting packaging>=22 (from pipenv) 3:53:36 PM: Downloading packaging-24.2-py3-none-any.whl.metadata (3.2 kB) 3:53:36 PM: Collecting setuptools>=67 (from pipenv) 3:53:36 PM: Downloading setuptools-76.0.0-py3-none-any.whl.metadata (6.7 kB) 3:53:36 PM: Collecting virtualenv>=20.24.2 (from pipenv) 3:53:36 PM: Downloading virtualenv-20.29.3-py3-none-any.whl.metadata (4.5 kB) 3:53:37 PM: Collecting distlib<1,>=0.3.7 (from virtualenv>=20.24.2->pipenv) 3:53:37 PM: Downloading distlib-0.3.9-py2.py3-none-any.whl.metadata (5.2 kB) 3:53:37 PM: Collecting filelock<4,>=3.12.2 (from virtualenv>=20.24.2->pipenv) 3:53:37 PM: Downloading filelock-3.17.0-py3-none-any.whl.metadata (2.9 kB) 3:53:37 PM: Collecting platformdirs<5,>=3.9.1 (from virtualenv>=20.24.2->pipenv) 3:53:37 PM: Downloading platformdirs-4.3.6-py3-none-any.whl.metadata (11 kB) 3:53:37 PM: Downloading pipenv-2024.4.1-py3-none-any.whl (3.0 MB) 3:53:37 PM: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.0/3.0 MB 23.8 MB/s eta 0:00:00 3:53:37 PM: Downloading packaging-24.2-py3-none-any.whl (65 kB) 3:53:37 PM: Downloading setuptools-76.0.0-py3-none-any.whl (1.2 MB) 3:53:37 PM: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 54.2 MB/s eta 0:00:00 3:53:37 PM: Downloading virtualenv-20.29.3-py3-none-any.whl (4.3 MB) 3:53:37 PM: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.3/4.3 MB 129.7 MB/s eta 0:00:00 3:53:37 PM: Downloading certifi-2025.1.31-py3-none-any.whl (166 kB) 3:53:37 PM: Downloading distlib-0.3.9-py2.py3-none-any.whl (468 kB) 3:53:37 PM: Downloading filelock-3.17.0-py3-none-any.whl (16 kB) 3:53:37 PM: Downloading platformdirs-4.3.6-py3-none-any.whl (18 kB) 3:53:37 PM: Installing collected packages: distlib, setuptools, platformdirs, packaging, filelock, certifi, virtualenv, pipenv 3:53:40 PM: Successfully installed certifi-2025.1.31 distlib-0.3.9 filelock-3.17.0 packaging-24.2 pipenv-2024.4.1 platformdirs-4.3.6 setuptools-76.0.0 virtualenv-20.29.3 3:53:40 PM: [notice] A new release of pip is available: 24.3.1 -> 25.0.1 3:53:40 PM: [notice] To update, run: pip install --upgrade pip 3:53:41 PM: Attempting Ruby version 2.7.2, read from environment 3:53:41 PM: Using Ruby version 2.7.2 3:53:42 PM: Started restoring cached go cache 3:53:42 PM: Finished restoring cached go cache 3:53:44 PM: go version go1.19.13 linux/amd64 3:53:44 PM: Using PHP version 8.0 3:53:46 PM: v22.14.0 is already installed. 3:53:47 PM: Now using node v22.14.0 (npm v10.9.2) 3:53:47 PM: Enabling Node.js Corepack 3:53:47 PM: Started restoring cached build plugins 3:53:47 PM: Finished restoring cached build plugins 3:53:47 PM: Started restoring cached corepack dependencies 3:53:47 PM: Finished restoring cached corepack dependencies 3:53:47 PM: No npm workspaces detected 3:53:47 PM: Started restoring cached node modules 3:53:47 PM: Finished restoring cached node modules 3:53:47 PM: Installing npm packages using npm version 10.9.2 3:54:16 PM: added 450 packages, and audited 451 packages in 28s 3:54:16 PM: 235 packages are looking for funding 3:54:16 PM: run `npm fund` for details 3:54:16 PM: found 0 vulnerabilities 3:54:16 PM: npm packages installed 3:54:16 PM: Successfully installed dependencies 3:54:16 PM: Starting build script 3:54:17 PM: Detected 1 framework(s) 3:54:17 PM: "next" at version "15.2.1" 3:54:17 PM: Section completed: initializing Building Failed 3:54:19 PM: Netlify Build 3:54:19 PM: ──────────────────────────────────────────────────────────────── 3:54:19 PM: ​ 3:54:19 PM: ❯ Version 3:54:19 PM: @netlify/build 29.59.2 3:54:19 PM: ​ 3:54:19 PM: ❯ Flags 3:54:19 PM: accountId: 66d1d0902d36e530c7d461d3 3:54:19 PM: baseRelDir: true 3:54:19 PM: buildId: 67cf513bbe3ea50008bd20fc 3:54:19 PM: deployId: 67cf513bbe3ea50008bd20fe 3:54:19 PM: ​ 3:54:19 PM: ❯ Current directory 3:54:19 PM: /opt/build/repo 3:54:19 PM: ​ 3:54:19 PM: ❯ Config file 3:54:19 PM: /opt/build/repo/netlify.toml 3:54:19 PM: ​ 3:54:19 PM: ❯ Context 3:54:19 PM: production 3:54:20 PM: ​ 3:54:20 PM: ❯ Using Next.js Runtime - v5.10.0 3:54:21 PM: No Next.js cache to restore 3:54:21 PM: ​ 3:54:21 PM: build.command from netlify.toml 3:54:21 PM: ──────────────────────────────────────────────────────────────── 3:54:21 PM: ​ 3:54:21 PM: $ npm run build 3:54:21 PM: > danielkliewer-portfolio@0.1.0 build 3:54:21 PM: > next build 3:54:22 PM: ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache 3:54:22 PM: ▲ Next.js 15.2.1 3:54:22 PM: Creating an optimized production build ... 3:54:35 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2) 3:54:30 PM: Retrying 1/3... 3:54:33 PM: ✓ Compiled successfully 3:54:33 PM: Linting and checking validity of types ... 3:54:34 PM: 3:54:34 PM: Failed to compile. 3:54:34 PM: ./src/components/MarkdownRenderer.tsx 3:54:34 PM: 107:25 Error: 'wrapper' is defined but never used. @typescript-eslint/no-unused-vars 3:54:34 PM: info - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/app/api-reference/config/eslint#disabling-rules 3:54:35 PM: ​ 3:54:35 PM: "build.command" failed 3:54:35 PM: ──────────────────────────────────────────────────────────────── 3:54:35 PM: ​ 3:54:35 PM: Error message 3:54:35 PM: Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1) 3:54:35 PM: ​ 3:54:35 PM: Error location 3:54:35 PM: In build.command from netlify.toml: 3:54:35 PM: npm run build 3:54:35 PM: ​ 3:54:35 PM: Resolved config 3:54:35 PM: build: 3:54:35 PM: command: npm run build 3:54:35 PM: commandOrigin: config 3:54:35 PM: environment: 3:54:35 PM: - STRIPE_SECRET_KEY 3:54:35 PM: publish: /opt/build/repo/.next 3:54:35 PM: publishOrigin: config 3:54:35 PM: functionsDirectory: /opt/build/repo/netlify/functions 3:54:35 PM: plugins: 3:54:35 PM: - inputs: {} 3:54:35 PM: origin: config 3:54:35 PM: package: '@netlify/plugin-nextjs' 3:54:35 PM: Build failed due to a user error: Build script returned non-zero exit code: 2 3:54:35 PM: Failing build: Failed to build site 3:54:35 PM: Finished processing build request in 1m8.091s Deploying Skipped Cleanup Skipped Post-processing
### Steps to Fix Your Netlify Build Failure 1. **Fix the TypeScript Warning in `MarkdownRenderer.tsx`** - The error about `'wrapper' is defined but never used` means there is an unused variable in your file. - If the variable is unnecessary, remove it from the code. - If it should be used, make sure it's properly referenced in the component. - If you want to ignore the error temporarily, add this above the variable: ```tsx // eslint-disable-next-line @typescript-eslint/no-unused-vars ``` 2. **Check Netlify Build Logs for More Errors** - The critical error is `Build script returned non-zero exit code: 2`. - This usually means your `npm run build` is failing. Try running it **locally**: ```sh npm run build ``` - If it fails locally, fix the errors before pushing to Netlify. 3. **Ensure Dependencies Are Installed Correctly** - Delete the `node_modules` folder and `package-lock.json`, then reinstall: ```sh rm -rf node_modules package-lock.json npm install ``` - Run the build again: ```sh npm run build ``` 4. **Check `netlify.toml` for Correct Build Settings** - Ensure you have the correct build command: ```toml [build] command = "npm run build" publish = "out" # Adjust if your project outputs elsewhere ``` 5. **Check for Next.js Version Issues** - You're using Next.js **15.2.1**, which may have breaking changes. - If your project worked before, try downgrading: ```sh npm install next@14 ``` 6. **Try a Clean Netlify Build** - In Netlify, go to **Site Settings → Build & Deploy**. - Click **Clear Cache & Retry Deploy**. If the issue persists, let me know what errors appear when running `npm run build` locally! 🚀
gpt-4o