I’m trying to deploy my site to Netlify and I keep getting this error. My site was working and was able to build before this build. Any ideas on what I can do? Also, I’m using Next.JS for the site.
3:43:14 PM: - info Generating static pages (2/6)
3:43:14 PM: - info Generating static pages (4/6)
3:43:14 PM: - info Generating static pages (6/6)
3:43:14 PM: > Export encountered errors on following paths:
3:43:14 PM: /account/page: /account
3:43:14 PM:
3:43:14 PM: build.command failed
3:43:14 PM: ────────────────────────────────────────────────────────────────
3:43:14 PM:
3:43:14 PM: Error message
3:43:14 PM: Command failed with exit code 1: next build (https://ntl.fyi/exit-code-1)
3:43:14 PM:
3:43:14 PM: Error location
3:43:14 PM: In Build command from Netlify app:
3:43:14 PM: next build
3:43:14 PM:
3:43:14 PM: Resolved config
3:43:14 PM: build:
3:43:14 PM: command: next build
3:43:14 PM: commandOrigin: ui
3:43:14 PM: environment:
3:43:14 PM: - NEXT_PRIVATE_TARGET
3:43:14 PM: publish: /opt/build/repo/.next
3:43:14 PM: publishOrigin: ui
3:43:14 PM: plugins:
3:43:14 PM: - inputs: {}
3:43:14 PM: origin: ui
3:43:14 PM: package: '@netlify/plugin-nextjs'
3:43:16 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:43:16 PM: Failing build: Failed to build site
3:43:17 PM: Finished processing build request in 43.454s
I’ve tried reuploading the site and adding "CI= npm run build" in my build and deploy settings.
2
Answers
You can try these steps to solve issue;
Inspect the problematic page: The error seems to be coming from /account/page: /account. Make sure everything is in order with that page file.
Try a local build: Run next build on your local machine. If it fails, the error message might give you more insight.
Review your data fetching: If you’re using getStaticProps or getServerSideProps, ensure they’re working as expected.
Look at your next.config.js: If you have this file, double-check it’s configured correctly.
Verify your environment variables: You’re using NEXT_PRIVATE_TARGET. Make sure it’s set correctly in your Netlify settings.
Update Next.js and Netlify plugin: If you’re not on the latest versions, consider upgrading.
You can try this:
Go to
Site configuration
. ClickEnvironment Variables
. Create two new environment variables:Key: NODE_VERSION
,Value: v14.17.0
Key: NPM_VERSION
,Value: 9.3.0
/* Specify the value of the version that is used in your project */
After setting this, try deploying the site again. This might fix the issue.