Deploy Error: Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)

Hello guys, i hope you are well.

I am a newbie develop, and it is my first time making a deploy.

In this time show me this error:

11:50:09 AM: build-image version: d55944c047ef0aee2ac01971edde72cb2a50acfe (focal)
11:50:09 AM: build-image tag: v4.16.1
11:50:09 AM: buildbot version: 9c7f73764568fa60950499e818e0d097bd15af19
11:50:09 AM: Building without cache
11:50:09 AM: Starting to prepare the repo for build
11:50:09 AM: No cached dependencies found. Cloning fresh repo
11:50:09 AM: git clone https://github.com/OneGuabaya/dashboard
11:50:09 AM: Preparing Git Reference refs/heads/main
11:50:09 AM: Parsing package.json dependencies
11:50:11 AM: Section completed: initializing
11:50:11 AM: Starting build script
11:50:11 AM: Installing dependencies
11:50:11 AM: Python version set to 2.7
11:50:11 AM: v16.19.0 is already installed.
11:50:12 AM: Now using node v16.19.0 (npm v8.19.3)
11:50:12 AM: Enabling node corepack
11:50:12 AM: Started restoring cached build plugins
11:50:12 AM: Finished restoring cached build plugins
11:50:12 AM: Attempting ruby version 2.7.2, read from environment
11:50:13 AM: Using ruby version 2.7.2
11:50:13 AM: Using PHP version 8.0
11:50:13 AM: No npm workspaces detected
11:50:13 AM: Started restoring cached node modules
11:50:13 AM: Finished restoring cached node modules
11:50:13 AM: Installing NPM modules using NPM version 8.19.3
11:50:15 AM: npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
11:50:22 AM: added 358 packages, and audited 360 packages in 9s
11:50:22 AM: 89 packages are looking for funding
11:50:22 AM: run npm fund for details
11:50:22 AM: 3 high severity vulnerabilities
11:50:22 AM: To address all issues (including breaking changes), run:
11:50:22 AM: npm audit fix --force
11:50:22 AM: Run npm audit for details.
11:50:22 AM: NPM modules installed
11:50:22 AM: Creating package sha
11:50:22 AM: Started restoring cached go cache
11:50:22 AM: Finished restoring cached go cache
11:50:23 AM: go version go1.19.4 linux/amd64
11:50:23 AM: Detected 1 framework(s)
11:50:23 AM: “next” at version “13.0.6”
11:50:23 AM: Installing missing commands
11:50:23 AM: Verify run directory
11:50:24 AM: ​
11:50:24 AM: ────────────────────────────────────────────────────────────────
11:50:24 AM: Netlify Build
11:50:24 AM: ────────────────────────────────────────────────────────────────
11:50:24 AM: ​
11:50:24 AM: ❯ Version
11:50:24 AM: @netlify/build 29.1.2
11:50:24 AM: ​
11:50:24 AM: ❯ Flags
11:50:24 AM: baseRelDir: true
11:50:24 AM: buildId: 639f36afca15d514f87032b6
11:50:24 AM: deployId: 639f36afca15d514f87032b8
11:50:24 AM: ​
11:50:24 AM: ❯ Current directory
11:50:24 AM: /opt/build/repo
11:50:24 AM: ​
11:50:24 AM: ❯ Config file
11:50:24 AM: /opt/build/repo/netlify.toml
11:50:24 AM: ​
11:50:24 AM: ❯ Context
11:50:24 AM: production
11:50:25 AM: ​
11:50:25 AM: ❯ Installing plugins
11:50:25 AM: - @netlify/plugin-nextjs@4.29.3
11:50:32 AM: ​
11:50:32 AM: ❯ Using Next.js Runtime - v4.29.3
11:50:34 AM: ​
11:50:34 AM: ────────────────────────────────────────────────────────────────
11:50:34 AM: 1. @netlify/plugin-nextjs (onPreBuild event)
11:50:34 AM: ────────────────────────────────────────────────────────────────
11:50:34 AM: ​
11:50:34 AM: No Next.js cache to restore.
11:50:34 AM: Netlify configuration property “build.environment.NEXT_PRIVATE_TARGET” value changed.
11:50:34 AM: ​
11:50:34 AM: (@netlify/plugin-nextjs onPreBuild completed in 19ms)
11:50:34 AM: ​
11:50:34 AM: ────────────────────────────────────────────────────────────────
11:50:34 AM: 2. build.command from netlify.toml
11:50:34 AM: ────────────────────────────────────────────────────────────────
11:50:34 AM: ​
11:50:34 AM: $ npm run build
11:50:34 AM: > dashboard@0.1.0 build
11:50:34 AM: > next build
11:50:34 AM: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: no-cache | Next.js
11:50:34 AM: info - Linting and checking validity of types…
11:50:37 AM:
11:50:37 AM: Failed to compile.
11:50:37 AM: ./pages/index.js
11:50:37 AM: 106:15 Warning: React Hook useEffect has missing dependencies: ‘cant’, ‘cleanMounts’, ‘dates’, ‘pay’, and ‘props.data’. Either include them or remove the dependency array. If ‘setCant’ needs the current value of ‘props.data’, you can also switch to useReducer instead of useState and read ‘props.data’ in the reducer. react-hooks/exhaustive-deps
11:50:37 AM: ./components/Footer.js
11:50:37 AM: 13:17 Warning: Image elements must have an alt prop, either with meaningful text, or an empty string for decorative images. jsx-a11y/alt-text
11:50:37 AM: 23:33 Error: Missing “key” prop for element in iterator react/jsx-key
11:50:37 AM: 33:33 Error: Missing “key” prop for element in iterator react/jsx-key
11:50:37 AM: 42:31 Warning: Image elements must have an alt prop, either with meaningful text, or an empty string for decorative images. jsx-a11y/alt-text
11:50:37 AM: ./components/Header.js
11:50:37 AM: 12:17 Warning: Image elements must have an alt prop, either with meaningful text, or an empty string for decorative images. jsx-a11y/alt-text
11:50:37 AM: 31:33 Error: Missing “key” prop for element in iterator react/jsx-key
11:50:37 AM: info - Need to disable some ESLint rules? Learn more here: Basic Features: ESLint | Next.js
11:50:37 AM: ​
11:50:37 AM: ────────────────────────────────────────────────────────────────
11:50:37 AM: “build.command” failed
11:50:37 AM: ────────────────────────────────────────────────────────────────
11:50:37 AM: ​
11:50:37 AM: Error message
11:50:37 AM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
11:50:37 AM: ​
11:50:37 AM: Error location
11:50:37 AM: In build.command from netlify.toml:
11:50:37 AM: npm run build
11:50:37 AM: ​
11:50:37 AM: Resolved config
11:50:37 AM: build:
11:50:37 AM: command: npm run build
11:50:37 AM: commandOrigin: config
11:50:37 AM: environment:
11:50:37 AM: - CI
11:50:38 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)
11:50:37 AM: - NEXT_USE_NETLIFY_EDGE
11:50:37 AM: - NEXT_PRIVATE_TARGET
11:50:37 AM: publish: /opt/build/repo/.next
11:50:37 AM: publishOrigin: config
11:50:37 AM: functionsDirectory: /opt/build/repo/functions
11:50:37 AM: plugins:
11:50:37 AM: - inputs: {}
11:50:37 AM: origin: ui
11:50:37 AM: package: ‘@netlify/plugin-nextjs’
11:50:37 AM: redirects:
11:50:37 AM: - from: /*
status: 200
to: /.netlify/functions/:splat
redirectsOrigin: config
Caching artifacts
11:50:37 AM: Started saving node modules
11:50:37 AM: Finished saving node modules
11:50:37 AM: Started saving build plugins
11:50:37 AM: Finished saving build plugins
11:50:37 AM: Started saving pip cache
11:50:37 AM: Finished saving pip cache
11:50:37 AM: Started saving emacs cask dependencies
11:50:37 AM: Finished saving emacs cask dependencies
11:50:37 AM: Started saving maven dependencies
11:50:37 AM: Finished saving maven dependencies
11:50:37 AM: Started saving boot dependencies
11:50:37 AM: Finished saving boot dependencies
11:50:37 AM: Started saving rust rustup cache
11:50:37 AM: Finished saving rust rustup cache
11:50:37 AM: Started saving go dependencies
11:50:37 AM: Finished saving go dependencies
11:50:38 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:50:38 AM: Failing build: Failed to build site
11:50:38 AM: Finished processing build request in 29.615699915s

How i can to solve this problem?

My repo is this: https://github.com/OneGuabaya/dashboard.git

Sorry for my bad english, thank you very much for your help!

Please fix the warnings in your code, or disable the ESLint rules as explained on that link.

Oh thanks! ready i dissable ESLint but the error persist, now throws this error:

12:23:28 PM: build-image version: d55944c047ef0aee2ac01971edde72cb2a50acfe (focal)
12:23:28 PM: build-image tag: v4.16.1
12:23:28 PM: buildbot version: 9c7f73764568fa60950499e818e0d097bd15af19
12:23:28 PM: Fetching cached dependencies
12:23:28 PM: Failed to fetch cache, continuing with build
12:23:28 PM: Starting to prepare the repo for build
12:23:28 PM: No cached dependencies found. Cloning fresh repo
12:23:28 PM: git clone https://github.com/OneGuabaya/dashboard
12:23:28 PM: Preparing Git Reference refs/heads/main
12:23:28 PM: Parsing package.json dependencies
12:23:29 PM: Different build command detected, going to use the one specified in the Netlify configuration file: ‘npm run build’ versus ‘CI= “npm run build”’ in the Netlify UI
12:23:29 PM: Section completed: initializing
12:23:30 PM: Starting build script
12:23:30 PM: Installing dependencies
12:23:30 PM: Python version set to 2.7
12:23:30 PM: v16.19.0 is already installed.
12:23:31 PM: Now using node v16.19.0 (npm v8.19.3)
12:23:31 PM: Enabling node corepack
12:23:31 PM: Started restoring cached build plugins
12:23:31 PM: Finished restoring cached build plugins
12:23:31 PM: Attempting ruby version 2.7.2, read from environment
12:23:31 PM: Using ruby version 2.7.2
12:23:32 PM: Using PHP version 8.0
12:23:32 PM: No npm workspaces detected
12:23:32 PM: Started restoring cached node modules
12:23:32 PM: Finished restoring cached node modules
12:23:32 PM: Installing NPM modules using NPM version 8.19.3
12:23:34 PM: npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
12:23:41 PM: added 358 packages, and audited 360 packages in 9s
12:23:41 PM: 89 packages are looking for funding
12:23:41 PM: run npm fund for details
12:23:41 PM: 3 high severity vulnerabilities
12:23:41 PM: To address all issues (including breaking changes), run:
12:23:41 PM: npm audit fix --force
12:23:41 PM: Run npm audit for details.
12:23:41 PM: NPM modules installed
12:23:41 PM: Creating package sha
12:23:41 PM: Started restoring cached go cache
12:23:41 PM: Finished restoring cached go cache
12:23:41 PM: go version go1.19.4 linux/amd64
12:23:41 PM: Detected 1 framework(s)
12:23:41 PM: “next” at version “13.0.6”
12:23:41 PM: Installing missing commands
12:23:41 PM: Verify run directory
12:23:43 PM: ​
12:23:43 PM: ────────────────────────────────────────────────────────────────
12:23:43 PM: Netlify Build
12:23:43 PM: ────────────────────────────────────────────────────────────────
12:23:43 PM: ​
12:23:43 PM: ❯ Version
12:23:43 PM: @netlify/build 29.1.2
12:23:43 PM: ​
12:23:43 PM: ❯ Flags
12:23:43 PM: baseRelDir: true
12:23:43 PM: buildId: 639f3e7e8cf37d00092a5010
12:23:43 PM: deployId: 639f3e7e8cf37d00092a5012
12:23:43 PM: ​
12:23:43 PM: ❯ Current directory
12:23:43 PM: /opt/build/repo
12:23:43 PM: ​
12:23:43 PM: ❯ Config file
12:23:43 PM: /opt/build/repo/netlify.toml
12:23:43 PM: ​
12:23:43 PM: ❯ Context
12:23:43 PM: production
12:23:43 PM: ​
12:23:43 PM: ❯ Installing plugins
12:23:43 PM: - @netlify/plugin-nextjs@4.29.3
12:23:53 PM: ​
12:23:53 PM: ❯ Using Next.js Runtime - v4.29.3
12:23:54 PM: ​
12:23:54 PM: ────────────────────────────────────────────────────────────────
12:23:54 PM: 1. @netlify/plugin-nextjs (onPreBuild event)
12:23:54 PM: ────────────────────────────────────────────────────────────────
12:23:54 PM: ​
12:23:54 PM: No Next.js cache to restore.
12:23:54 PM: Netlify configuration property “build.environment.NEXT_PRIVATE_TARGET” value changed.
12:23:55 PM: ​
12:23:55 PM: (@netlify/plugin-nextjs onPreBuild completed in 28ms)
12:23:55 PM: ​
12:23:55 PM: ────────────────────────────────────────────────────────────────
12:23:55 PM: 2. build.command from netlify.toml
12:23:55 PM: ────────────────────────────────────────────────────────────────
12:23:55 PM: ​
12:23:55 PM: $ npm run build
12:23:55 PM: > dashboard@0.1.0 build
12:23:55 PM: > next build
12:23:55 PM: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: no-cache | Next.js
12:23:55 PM: info - Skipping linting
12:23:55 PM: info - Checking validity of types…
12:23:56 PM: info - Creating an optimized production build…
12:24:08 PM: info - Compiled successfully
12:24:08 PM: info - Collecting page data…
12:24:13 PM: info - Generating static pages (0/3)
12:24:14 PM: Error occurred prerendering page “/”. Read more: prerender-error | Next.js
12:24:14 PM: Error: connect ECONNREFUSED 127.0.0.1:8888
12:24:14 PM: at Function.AxiosError.from (/opt/build/repo/node_modules/axios/dist/node/axios.cjs:785:14)
12:24:14 PM: at RedirectableRequest.handleRequestError (/opt/build/repo/node_modules/axios/dist/node/axios.cjs:2733:25)
12:24:14 PM: at RedirectableRequest.emit (node:events:513:28)
12:24:14 PM: at ClientRequest.eventHandlers. (/opt/build/repo/node_modules/follow-redirects/index.js:14:24)
12:24:14 PM: at ClientRequest.emit (node:events:513:28)
12:24:14 PM: at Socket.socketErrorListener (node:_http_client:494:9)
12:24:14 PM: at Socket.emit (node:events:513:28)
12:24:14 PM: at emitErrorNT (node:internal/streams/destroy:157:8)
12:24:14 PM: at emitErrorCloseNT (node:internal/streams/destroy:122:3)
12:24:14 PM: at processTicksAndRejections (node:internal/process/task_queues:83:21)
12:24:14 PM: info - Generating static pages (3/3)
12:24:14 PM: > Build error occurred
12:24:14 PM: Error: Export encountered errors on following paths:
12:24:14 PM: /
12:24:14 PM: at /opt/build/repo/node_modules/next/dist/export/index.js:408:19
12:24:14 PM: at runMicrotasks ()
12:24:14 PM: at processTicksAndRejections (node:internal/process/task_queues:96:5)
12:24:14 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
12:24:14 PM: at async /opt/build/repo/node_modules/next/dist/build/index.js:1342:21
12:24:14 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
12:24:14 PM: at async /opt/build/repo/node_modules/next/dist/build/index.js:1202:17
12:24:14 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
12:24:14 PM: at async Object.build [as default] (/opt/build/repo/node_modules/next/dist/build/index.js:65:29)
12:24:15 PM: ​
12:24:15 PM: ────────────────────────────────────────────────────────────────
12:24:15 PM: “build.command” failed
12:24:15 PM: ────────────────────────────────────────────────────────────────
12:24:15 PM: ​
12:24:15 PM: Error message
12:24:15 PM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
12:24:15 PM: ​
12:24:15 PM: Error location
12:24:15 PM: In build.command from netlify.toml:
12:24:15 PM: npm run build
12:24:15 PM: ​
12:24:15 PM: Resolved config
12:24:15 PM: build:
12:24:15 PM: command: npm run build
12:24:16 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)
12:24:15 PM: commandOrigin: config
12:24:15 PM: environment:
12:24:15 PM: - CI
12:24:15 PM: - NEXT_USE_NETLIFY_EDGE
12:24:15 PM: - NEXT_PRIVATE_TARGET
12:24:15 PM: publish: /opt/build/repo/.next
12:24:15 PM: publishOrigin: config
12:24:15 PM: functionsDirectory: /opt/build/repo/functions
12:24:15 PM: plugins:
12:24:15 PM: - inputs: {}
12:24:15 PM: origin: ui
12:24:15 PM: package: ‘@netlify/plugin-nextjs’
12:24:15 PM: redirects:
12:24:15 PM: - from: /*
status: 200
to: /.netlify/functions/:splat
redirectsOrigin: config
Caching artifacts
12:24:15 PM: Started saving node modules
12:24:15 PM: Finished saving node modules
12:24:15 PM: Started saving build plugins
12:24:15 PM: Finished saving build plugins
12:24:15 PM: Started saving pip cache
12:24:15 PM: Finished saving pip cache
12:24:15 PM: Started saving emacs cask dependencies
12:24:15 PM: Finished saving emacs cask dependencies
12:24:15 PM: Started saving maven dependencies
12:24:15 PM: Finished saving maven dependencies
12:24:15 PM: Started saving boot dependencies
12:24:15 PM: Finished saving boot dependencies
12:24:15 PM: Started saving rust rustup cache
12:24:15 PM: Finished saving rust rustup cache
12:24:15 PM: Started saving go dependencies
12:24:15 PM: Finished saving go dependencies
12:24:16 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:24:16 PM: Failing build: Failed to build site
12:24:16 PM: Finished processing build request in 48.585523102s

You seem to be trying to connect to localhost. But since, I can see something related to Axios below that, I’m assuming you’re using Axios. So, if you use a relative path in a Node.js environment, Axios tries to connect to localhost. Make sure you use absolute URLs.

I see, but my endpoint is configured in my repo. How i can use it if the page is not deployed yet?

Sorry for the inconvenients!

Could you show what exactly you’re trying? Why do you need to access a page from your website before it’s deployed?

I make a new route with with netlify functions to consume data to postgres DB.

I use axios to use this route and covert the data in JSON, this JSON feed the page.

OK, you’re welcome to do that, but we’d recommend setting up two separate sites:

  • one with your function
  • one that uses your already-deployed function

This will probably work better than trying to develop a function you are deploying at the same time :smiley:

Hi! So many thanks for your support, i make this and my website is 100% functional.

Thank you very much.