Home
Support Forums

I cannot deploy my nextjs site

When ever i try to deploy my nextjs site i get these errors

11:39:27 PM: Build ready to start
11:39:29 PM: build-image version: 653805ca4a64301556e56dc4b321ef8fc20cbb7c
11:39:29 PM: build-image tag: v3.8.2
11:39:29 PM: buildbot version: d8b6cf9bb9d4dfebc897269cd3f8952bd0d27997
11:39:29 PM: Fetching cached dependencies
11:39:29 PM: Failed to fetch cache, continuing with build
11:39:29 PM: Starting to prepare the repo for build
11:39:30 PM: No cached dependencies found. Cloning fresh repo
11:39:30 PM: git clone https://github.com/IshanKBG/ishankbg.dev
11:39:31 PM: Preparing Git Reference refs/heads/main
11:39:31 PM: Parsing package.json dependencies
11:39:32 PM: Starting build script
11:39:32 PM: Installing dependencies
11:39:32 PM: Python version set to 2.7
11:39:33 PM: v12.18.0 is already installed.
11:39:34 PM: Now using node v12.18.0 (npm v6.14.4)
11:39:34 PM: Started restoring cached build plugins
11:39:34 PM: Finished restoring cached build plugins
11:39:34 PM: Attempting ruby version 2.7.2, read from environment
11:39:35 PM: Using ruby version 2.7.2
11:39:35 PM: Using PHP version 5.6
11:39:35 PM: Started restoring cached node modules
11:39:35 PM: Finished restoring cached node modules
11:39:36 PM: Installing NPM modules using NPM version 6.14.4
11:39:43 PM: npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
11:39:44 PM: npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
11:39:52 PM: > deasync@0.1.21 install /opt/build/repo/node_modules/deasync
11:39:52 PM: > node ./build.js
11:39:52 PM: `linux-x64-node-12` exists; testing
11:39:52 PM: Binary is fine; exiting
11:39:52 PM: > esbuild@0.12.17 postinstall /opt/build/repo/node_modules/esbuild
11:39:52 PM: > node install.js
11:39:53 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
11:39:53 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
11:39:53 PM: added 499 packages from 405 contributors and audited 500 packages in 16.977s
11:39:53 PM: 121 packages are looking for funding
11:39:53 PM:   run `npm fund` for details
11:39:53 PM: found 0 vulnerabilities
11:39:54 PM: NPM modules installed
11:39:54 PM: Started restoring cached go cache
11:39:54 PM: Finished restoring cached go cache
11:39:54 PM: go version go1.14.4 linux/amd64
11:39:54 PM: go version go1.14.4 linux/amd64
11:39:54 PM: Installing missing commands
11:39:54 PM: Verify run directory
11:39:54 PM: ​
11:39:54 PM: ────────────────────────────────────────────────────────────────
11:39:54 PM:   Netlify Build                                                 
11:39:54 PM: ────────────────────────────────────────────────────────────────
11:39:54 PM: ​
11:39:54 PM: ❯ Version
11:39:54 PM:   @netlify/build 17.9.1
11:39:54 PM: ​
11:39:54 PM: ❯ Flags
11:39:54 PM:   deployId: 610c2957cf9cfa0008756d9c
11:39:54 PM: ​
11:39:54 PM: ❯ Current directory
11:39:54 PM:   /opt/build/repo
11:39:54 PM: ​
11:39:54 PM: ❯ Config file
11:39:54 PM:   No config file was defined: using default values.
11:39:54 PM: ​
11:39:54 PM: ❯ Context
11:39:54 PM:   production
11:39:55 PM: ​
11:39:55 PM: ❯ Installing plugins
11:39:55 PM:    - @netlify/plugin-nextjs@3.8.0
11:40:15 PM: ​
11:40:15 PM: ❯ Loading plugins
11:40:15 PM:    - @netlify/plugin-nextjs@3.8.0 from Netlify app
11:40:15 PM: ​
11:40:15 PM: ────────────────────────────────────────────────────────────────
11:40:15 PM:   1. onPreBuild command from @netlify/plugin-nextjs             
11:40:15 PM: ────────────────────────────────────────────────────────────────
11:40:15 PM: ​
11:40:15 PM: Using Next.js 11.0.1
11:40:15 PM: info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
11:40:15 PM: The "target" config property must be one of "serverless", "experimental-serverless-trace". Building with "serverless" target.
11:40:16 PM: info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
11:40:16 PM: No Next.js cache to restore.
11:40:16 PM: ​
11:40:16 PM: (@netlify/plugin-nextjs onPreBuild completed in 926ms)
11:40:16 PM: ​
11:40:16 PM: ────────────────────────────────────────────────────────────────
11:40:16 PM:   2. Build command from Netlify app                             
11:40:16 PM: ────────────────────────────────────────────────────────────────
11:40:16 PM: ​
11:40:16 PM: $ npm run build
11:40:16 PM: > @ build /opt/build/repo
11:40:16 PM: > next build
11:40:17 PM: info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
11:40:17 PM: info  - Checking validity of types...
11:40:17 PM: warn  - No ESLint configuration detected. Run next lint to begin setup
11:40:17 PM: info  - Creating an optimized production build...
11:40:34 PM: Failed to compile.
11:40:34 PM: 
11:40:34 PM: ModuleNotFoundError: Module not found: Error: Can't resolve 'acorn' in '/opt/build/repo/node_modules/acorn-jsx'
11:40:34 PM: > Build error occurred
11:40:34 PM: Error: > Build failed because of webpack errors
11:40:34 PM:     at /opt/build/repo/node_modules/next/dist/build/index.js:15:924
11:40:34 PM:     at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:6:584)
11:40:34 PM: npm ERR! code ELIFECYCLE
11:40:34 PM: npm ERR! errno 1
11:40:34 PM: npm ERR! @ build: `next build`
11:40:34 PM: npm ERR! Exit status 1
11:40:34 PM: npm ERR!
11:40:34 PM: npm ERR! Failed at the @ build script.
11:40:34 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
11:40:34 PM: npm ERR! A complete log of this run can be found in:
11:40:34 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-08-05T18_10_34_681Z-debug.log
11:40:34 PM: ​
11:40:34 PM: ────────────────────────────────────────────────────────────────
11:40:34 PM:   "build.command" failed                                        
11:40:34 PM: ────────────────────────────────────────────────────────────────
11:40:34 PM: ​
11:40:34 PM:   Error message
11:40:34 PM:   Command failed with exit code 1: npm run build
11:40:34 PM: ​
11:40:34 PM:   Error location
11:40:34 PM:   In Build command from Netlify app:
11:40:34 PM:   npm run build
11:40:34 PM: ​
11:40:34 PM:   Resolved config
11:40:34 PM:   build:
11:40:34 PM:     command: npm run build
11:40:34 PM:     commandOrigin: ui
11:40:34 PM:     publish: /opt/build/repo/.next
11:40:34 PM:     publishOrigin: ui
11:40:34 PM:   plugins:
11:40:34 PM:     - inputs: {}
11:40:34 PM:       origin: ui
11:40:34 PM:       package: '@netlify/plugin-nextjs'
11:40:35 PM: Caching artifacts
11:40:35 PM: Started saving node modules
11:40:35 PM: Finished saving node modules
11:40:35 PM: Started saving build plugins
11:40:35 PM: Finished saving build plugins
11:40:35 PM: Started saving pip cache
11:40:35 PM: Finished saving pip cache
11:40:35 PM: Started saving emacs cask dependencies
11:40:35 PM: Finished saving emacs cask dependencies
11:40:35 PM: Started saving maven dependencies
11:40:35 PM: Finished saving maven dependencies
11:40:35 PM: Started saving boot dependencies
11:40:35 PM: Finished saving boot dependencies
11:40:35 PM: Started saving rust rustup cache
11:40:35 PM: Finished saving rust rustup cache
11:40:35 PM: Started saving go dependencies
11:40:35 PM: Finished saving go dependencies
11:40:37 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:40:37 PM: Creating deploy upload records
11:40:37 PM: Failing build: Failed to build site
11:40:37 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
11:40:37 PM: Finished processing build request in 1m8.396359506s

I am usihg github for deploying.

Hi there :wave:

Thanks so much for reaching out, and welcome to the Netlify Forums! Sorry to hear you have encountered difficulties.

A good starting point is this Support Guide that discusses preliminary debugging steps when you encounter issues like this.

Should you try those steps and still encounter issues, please respond to this post with the following:

  1. A link to your site
  2. A link to your repo
  3. Your package.json
  4. Steps you tried that did not work.

Thank you!

1 Like

i am now getting some new errors now
Logs:

──────────────────────────────────────────────────────────
6:18:08 AM: ​
6:18:08 AM: Using Next.js 11.0.1
6:18:08 AM: info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
6:18:09 AM: The "target" config property must be one of "serverless", "experimental-serverless-trace". Building with "serverless" target.
6:18:09 AM: info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
6:18:09 AM: No Next.js cache to restore.
6:18:09 AM: ​
6:18:09 AM: (@netlify/plugin-nextjs onPreBuild completed in 1.3s)
6:18:09 AM: ​
6:18:09 AM: ────────────────────────────────────────────────────────────────
6:18:09 AM:   2. Build command from Netlify app                             
6:18:09 AM: ────────────────────────────────────────────────────────────────
6:18:09 AM: ​
6:18:09 AM: $ CI=' ' npm run build
6:18:10 AM: > build
6:18:10 AM: > next build
6:18:11 AM: info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
6:18:11 AM: info  - Checking validity of types...
6:18:11 AM: warn  - No ESLint configuration detected. Run next lint to begin setup
6:18:11 AM: info  - Creating an optimized production build...
6:18:33 AM: (node:1756) [DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE] DeprecationWarning: Chunk.hasEntryModule: Use new ChunkGraph API
6:18:33 AM: (Use `node --trace-deprecation ...` to show where the warning was created)
6:18:33 AM: (node:1756) [DEP_WEBPACK_CHUNK_ADD_MODULE] DeprecationWarning: Chunk.addModule: Use new ChunkGraph API
6:18:37 AM: warn  - Compiled with warnings
6:18:37 AM: ./node_modules/keyv/src/index.js
6:18:37 AM: Critical dependency: the request of a dependency is an expression
6:18:37 AM: ./node_modules/next/dist/next-server/server/load-components.js
6:18:37 AM: Critical dependency: the request of a dependency is an expression
6:18:37 AM: ./node_modules/next/dist/next-server/server/load-components.js
6:18:37 AM: Critical dependency: the request of a dependency is an expression
6:18:37 AM: ./node_modules/next/dist/next-server/server/load-components.js
6:18:37 AM: Critical dependency: the request of a dependency is an expression
6:18:37 AM: ./node_modules/next/dist/next-server/server/require.js
6:18:37 AM: Critical dependency: the request of a dependency is an expression
6:18:37 AM: ./node_modules/next/dist/next-server/server/require.js
6:18:37 AM: Critical dependency: the request of a dependency is an expression
6:18:37 AM: ./node_modules/next/dist/next-server/server/require.js
6:18:37 AM: Critical dependency: the request of a dependency is an expression
6:18:37 AM: info  - Collecting page data...
6:18:38 AM: info  - Generating static pages (0/5)
6:18:39 AM: info  - Generating static pages (1/5)
6:18:39 AM: info  - Generating static pages (2/5)
6:18:39 AM: info  - Generating static pages (3/5)
6:18:39 AM: /opt/build/repo
6:18:39 AM: info  - Generating static pages (5/5)
6:18:39 AM: info  - Finalizing page optimization...
6:18:39 AM: Page                                Size     First Load JS
6:18:39 AM: β”Œ β—‹ /                               2.59 kB        68.4 kB
6:18:39 AM: β”œ   /_app                           0 B            65.8 kB
6:18:39 AM: β”œ β—‹ /404                            1.41 kB        67.2 kB
6:18:39 AM: β”œ ● /lessons                        1.84 kB        67.7 kB
6:18:39 AM: β”” ● /lessons/[slug]                 5.78 kB        71.6 kB
6:18:39 AM:     β”” /lessons/what-is-programming
6:18:39 AM: + First Load JS shared by all       65.8 kB
6:18:39 AM:   β”œ chunks/framework.dacd59.js      42.1 kB
6:18:39 AM:   β”œ chunks/main.f06480.js           20.3 kB
6:18:39 AM:   β”œ chunks/pages/_app.cb4107.js     2.53 kB
6:18:39 AM:   β”” chunks/webpack.652a13.js        861 B
6:18:39 AM: Ξ»  (Lambda)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
6:18:39 AM: β—‹  (Static)  automatically rendered as static HTML (uses no initial props)
6:18:39 AM: ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
6:18:39 AM:    (ISR)     incremental static regeneration (uses revalidate in getStaticProps)
6:18:39 AM: ​
6:18:39 AM: (build.command completed in 30s)
6:18:39 AM: ​
6:18:39 AM: ────────────────────────────────────────────────────────────────
6:18:39 AM:   3. onBuild command from @netlify/plugin-nextjs                
6:18:39 AM: ────────────────────────────────────────────────────────────────
6:18:39 AM: ​
6:18:39 AM: Detected Next.js site. Copying files...
6:18:39 AM: ** Running Next on Netlify package **
6:18:39 AM: πŸš€ Next on Netlify πŸš€
6:18:39 AM: 🌍️ Copying public folder to /opt/build/repo/.next
6:18:39 AM: πŸ’Ό Copying static NextJS assets to /opt/build/repo/.next
6:18:39 AM: πŸ’« Setting up API endpoints as Netlify Functions in /opt/build/repo/netlify/functions
6:18:39 AM: πŸ’« Setting up pages with getInitialProps as Netlify Functions in /opt/build/repo/netlify/functions
6:18:39 AM: πŸ’« Setting up pages with getServerSideProps as Netlify Functions in /opt/build/repo/netlify/functions
6:18:39 AM: πŸ”₯ Copying pre-rendered pages with getStaticProps and JSON data to /opt/build/repo/.next
6:18:39 AM: πŸ’« Setting up pages with getStaticProps and fallback: true as Netlify Functions in /opt/build/repo/netlify/functions
6:18:39 AM: πŸ’« Setting up pages with getStaticProps and revalidation interval as Netlify Functions in /opt/build/repo/netlify/functions
6:18:39 AM: πŸ”₯ Copying pre-rendered pages without props to /opt/build/repo/.next
6:18:39 AM: Building 8 pages
6:18:39 AM: πŸ”€ Setting up redirects
6:18:39 AM: πŸ”€ Setting up headers
6:18:39 AM: βœ… Success! All done!
6:18:39 AM: ​
6:18:39 AM: (@netlify/plugin-nextjs onBuild completed in 95ms)
6:18:39 AM: ​
6:18:39 AM: ────────────────────────────────────────────────────────────────
6:18:39 AM:   4. Functions bundling                                         
6:18:39 AM: ────────────────────────────────────────────────────────────────
6:18:39 AM: ​
6:18:40 AM: Packaging Functions from netlify/functions directory:
6:18:40 AM:  - next_image/next_image.js
6:18:40 AM:  - next_lessons/next_lessons.js
6:18:40 AM:  - next_lessons_slug/next_lessons_slug.js
6:18:40 AM: ​
6:18:42 AM: ​
6:18:42 AM: ────────────────────────────────────────────────────────────────
6:18:42 AM:   Dependencies installation error                               
6:18:42 AM: ────────────────────────────────────────────────────────────────
6:18:42 AM: ​
6:18:42 AM:   Error message
6:18:42 AM:   A Netlify Function failed to require one of its dependencies.
6:18:42 AM:   Please make sure it is present in the site's top-level "package.json".​
6:18:42 AM:   In file "/opt/build/repo/netlify/functions/next_lessons/next_lessons.js"
6:18:42 AM:   Cannot find module 'pnpapi'
6:18:42 AM:   Require stack:
6:18:42 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/node_dependencies/resolve.js
6:18:42 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/node_dependencies/index.js
6:18:42 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/main.js
6:18:42 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/utils.js
6:18:42 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/index.js
6:18:42 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/commands/get.js
6:18:42 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/main.js
6:18:42 AM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/bin.js
6:18:42 AM: ​
6:18:42 AM:   Resolved config
6:18:42 AM:   build:
6:18:42 AM:     base: /opt/build/repo
6:18:42 AM:     command: CI=' ' npm run build
6:18:42 AM:     commandOrigin: ui
6:18:42 AM:     environment:
6:18:42 AM:       - NODE_VERSION
6:18:42 AM:       - NPM_VERSION
6:18:42 AM:     publish: /opt/build/repo/.next
6:18:42 AM:     publishOrigin: ui
6:18:42 AM:   functionsDirectory: /opt/build/repo/netlify/functions
6:18:42 AM:   plugins:
6:18:42 AM:     - inputs: {}
6:18:42 AM:       origin: ui
6:18:42 AM:       package: '@netlify/plugin-nextjs'
6:18:42 AM:   redirects:
6:18:42 AM:     - conditions:
6:18:42 AM:         Cookie: __prerender_bypass,__next_preview_data
6:18:42 AM:       force: true
6:18:42 AM:       from: /_next/data/-KsIKmmKHD31NndaEVyYF/lessons.json
6:18:42 AM:       status: 200
6:18:42 AM:       to: /.netlify/functions/next_lessons
6:18:42 AM:     - conditions:
6:18:42 AM:         Cookie: __prerender_bypass,__next_preview_data
6:18:42 AM:       force: true
6:18:42 AM:       from: /_next/data/-KsIKmmKHD31NndaEVyYF/lessons/what-is-programming.json
6:18:42 AM:       status: 200
6:18:42 AM:       to: /.netlify/functions/next_lessons_slug
6:18:42 AM:     - conditions:
6:18:42 AM:         Cookie: __prerender_bypass,__next_preview_data
6:18:42 AM:       force: true
6:18:42 AM:       from: /lessons
6:18:42 AM:       status: 200
6:18:42 AM:       to: /.netlify/functions/next_lessons
6:18:42 AM:     - conditions:
6:18:42 AM:         Cookie: __prerender_bypass,__next_preview_data
6:18:42 AM:       force: true
6:18:42 AM:       from: /lessons/what-is-programming
6:18:42 AM:       status: 200
6:18:42 AM:       to: /.netlify/functions/next_lessons_slug
6:18:42 AM:     - force: true
6:18:42 AM:       from: /_next/image*
6:18:42 AM:       query:
6:18:42 AM:         q: ':quality'
6:18:42 AM:         url: ':url'
6:18:42 AM:         w: ':width'
6:18:42 AM:       status: 301
6:18:42 AM:       to: /nextimg/:url/:width/:quality
6:18:50 AM:     - from: /nextimg/*      status: 200      to: /.netlify/functions/next_imageCaching artifacts
6:18:50 AM: Started saving node modules
6:18:50 AM: Finished saving node modules
6:18:50 AM: Started saving build plugins
6:18:50 AM: Finished saving build plugins
6:18:50 AM: Started saving pip cache
6:18:50 AM: Finished saving pip cache
6:18:50 AM: Started saving emacs cask dependencies
6:18:50 AM: Finished saving emacs cask dependencies
6:18:50 AM: Started saving maven dependencies
6:18:50 AM: Finished saving maven dependencies
6:18:50 AM: Started saving boot dependencies
6:18:50 AM: Finished saving boot dependencies
6:18:50 AM: Started saving rust rustup cache
6:18:50 AM: Finished saving rust rustup cache
6:18:50 AM: Started saving go dependencies
6:18:50 AM: Finished saving go dependencies
6:18:53 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
6:18:53 AM: Creating deploy upload records
6:18:53 AM: Failing build: Failed to build site
6:18:53 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2
6:18:53 AM: Finished processing build request in 2m0.333246253s

1)Site link:https://optimistic-heyrovsky-750554.netlify.app/
2)Repo: GitHub - IshanKBG/ishankbg.dev
3) package.json :

{
  "private": true,
  "scripts": {
    "dev": "next",
    "dev:watch": "next-remote-watch ./articles",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "esbuild": "^0.12.16",
    "gray-matter": "^4.0.2",
    "mdx-bundler": "^5.1.2",
    "next": "latest",
    "next-remote-watch": "1.0.0",
    "next-seo": "^4.26.0",
    "prism-react-renderer": "^1.2.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "rss": "^1.2.2",
    "sass": "^1.37.5",
    "use-sound": "^4.0.1"
  },
  "license": "MIT",
  "devDependencies": {

    "yaml-loader": "^0.6.0"
  }
}

4)I changed npm version to 7 and node version to 14 and also added CI=’ ’ npm run build but they didnt do much.

Hi @IshanKBG

Your repo is currently private. Are you willing to make it public so others can help troubleshoot your issues?

1 Like

Oh ya sorry for the inconvenience now it’s public @coelmay

Have had success deploying your code @IshanKBG.

  1. Added package-lock.json to .gitignore as possible corruption made sure it was removed from remote (GitHub) repository.

  2. There is a missing package pnpapi when Netlify’s Next.js plugin builds the functions.
    npm install pnpapi to add it.

  3. Used npm run build not CI=' ' npm run build as you had (your command may still work though.)

Site is deployed. There is an issue still in that there is a dialog that says No UI.

1 Like

Ya thanks for help and ya that No UI one is something I am developing
I added it as a placeholder
Actually the site isn’t completed yet

I did suspect that was the case.

1 Like