Issue while deploying Next APP

Hello Team,

I’m facing issue while deploying nextjs application on netlify . Followed steps as mentioned on site

I tried by clearing cache , replaced node-fetch with isomorphic-fetch with no luck.

7:25:15 PM: Build ready to start
7:25:18 PM: build-image version: 53b83b6bede2920f236b25b6f5a95334320dc849
7:25:18 PM: build-image tag: v3.6.0
7:25:18 PM: buildbot version: 8ae026ef4905d9174e416775c6b64aa19950569b
7:25:18 PM: Fetching cached dependencies
7:25:18 PM: Failed to fetch cache, continuing with build
7:25:18 PM: Starting to prepare the repo for build
7:25:18 PM: No cached dependencies found. Cloning fresh repo
7:25:18 PM: git clone https://github.com/Adityacs001/app-hrms
7:25:19 PM: Preparing Git Reference refs/heads/master
7:25:21 PM: Different build command detected, going to use the one specified in the Netlify configuration file: β€˜npm run build’ versus β€˜next build’ in the Netlify UI
7:25:21 PM: Starting build script
7:25:21 PM: Installing dependencies
7:25:21 PM: Python version set to 2.7
7:25:22 PM: v12.18.0 is already installed.
7:25:23 PM: Now using node v12.18.0 (npm v6.14.4)
7:25:23 PM: Started restoring cached build plugins
7:25:23 PM: Finished restoring cached build plugins
7:25:23 PM: Attempting ruby version 2.7.1, read from environment
7:25:24 PM: Using ruby version 2.7.1
7:25:24 PM: Using PHP version 5.6
7:25:24 PM: Started restoring cached node modules
7:25:24 PM: Finished restoring cached node modules
7:25:24 PM: Started restoring cached yarn cache
7:25:24 PM: Finished restoring cached yarn cache
7:25:24 PM: Installing yarn at version 1.22.4
7:25:24 PM: Installing Yarn!
7:25:24 PM: > Downloading tarball…
7:25:24 PM: [1/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz β†’ /tmp/yarn.tar.gz.pLtWLdh1H5
7:25:24 PM: % Total % Received % Xferd Average Speed Time Time Time Current
7:25:24 PM: Dload Upload Total Spent Left Speed
7:25:24 PM: 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
7:25:25 PM: 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
7:25:25 PM: 100 80 100 80 0 0 282 0 --:–:-- --:–:-- --:–:-- 281
7:25:25 PM: 100 93 100 93 0 0 157 0 --:–:-- --:–:-- --:–:-- 157
7:25:25 PM: 100 643 100 643 0 0 744 0 --:–:-- --:–:-- --:–:-- 744
7:25:26 PM: 0 0 0 0 0 0 0 0 --:–:-- 0:00:01 --:–:-- 0
7:25:26 PM: 100 1215k 100 1215k 0 0 941k 0 0:00:01 0:00:01 --:–:-- 5378k
7:25:26 PM: [2/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz.asc β†’ /tmp/yarn.tar.gz.pLtWLdh1H5.asc
7:25:26 PM: 100 84 100 84 0 0 3048 0 --:–:-- --:–:-- --:–:-- 3048
7:25:26 PM: 100 97 100 97 0 0 1737 0 --:–:-- --:–:-- --:–:-- 1737
7:25:26 PM: 100 647 100 647 0 0 7370 0 --:–:-- --:–:-- --:–:-- 7370
7:25:26 PM: 100 1028 100 1028 0 0 7798 0 --:–:-- --:–:-- --:–:-- 7798
7:25:26 PM: > Verifying integrity…
7:25:26 PM: gpg: Signature made Mon 09 Mar 2020 03:52:13 PM UTC using RSA key ID 69475BAA
7:25:26 PM: gpg: Good signature from β€œYarn Packaging yarn@dan.cx”
7:25:26 PM: gpg: WARNING: This key is not certified with a trusted signature!
7:25:26 PM: gpg: There is no indication that the signature belongs to the owner.
7:25:26 PM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907 BBB7 1646 B01B 86E5 0310
7:25:26 PM: Subkey fingerprint: 6D98 490C 6F1A CDDD 448E 4595 4F77 6793 6947 5BAA
7:25:26 PM: > GPG signature looks good
7:25:26 PM: > Extracting to ~/.yarn…
7:25:26 PM: > Adding to $PATH…
7:25:26 PM: > Successfully installed Yarn 1.22.4! Please open another terminal where the yarn command will now be available.
7:25:27 PM: Installing NPM modules using Yarn version 1.22.4
7:25:27 PM: yarn install v1.22.4
7:25:27 PM: [1/4] Resolving packages…
7:25:27 PM: [2/4] Fetching packages…
7:25:39 PM: info fsevents@2.1.3: The platform β€œlinux” is incompatible with this module.
7:25:39 PM: info β€œfsevents@2.1.3” is an optional dependency and failed compatibility check. Excluding it from installation.
7:25:39 PM: info fsevents@1.2.13: The platform β€œlinux” is incompatible with this module.
7:25:39 PM: info β€œfsevents@1.2.13” is an optional dependency and failed compatibility check. Excluding it from installation.
7:25:39 PM: [3/4] Linking dependencies…
7:25:39 PM: warning " > cogo-toast@4.2.3" has unmet peer dependency β€œprop-types@^15.6.2”.
7:25:39 PM: warning " > cogo-toast@4.2.3" has incorrect peer dependency β€œreact@^16.8.0”.
7:25:39 PM: warning " > cogo-toast@4.2.3" has incorrect peer dependency β€œreact-dom@^16.8.0”.
7:25:39 PM: warning β€œ@netlify/plugin-nextjs > next-on-netlify > @sls-next/lambda-at-edge > @zeit/node-file-trace > acorn-export-ns-from@0.1.0” has incorrect peer dependency β€œacorn@^6.0.1”.
7:25:39 PM: warning β€œ@netlify/plugin-nextjs > next-on-netlify > @sls-next/lambda-at-edge > @aws-sdk/client-s3 > @aws-sdk/middleware-retry > react-native-get-random-values@1.5.0” has unmet peer dependency β€œreact-native@>=0.56”.
7:25:45 PM: [4/4] Building fresh packages…
7:25:48 PM: Done in 21.25s.
7:25:48 PM: NPM modules installed using Yarn
7:25:48 PM: Started restoring cached go cache
7:25:48 PM: Finished restoring cached go cache
7:25:49 PM: go version go1.14.4 linux/amd64
7:25:49 PM: go version go1.14.4 linux/amd64
7:25:49 PM: Installing missing commands
7:25:49 PM: Verify run directory
7:25:50 PM: ​
7:25:50 PM: ────────────────────────────────────────────────────────────────
7:25:50 PM: Netlify Build
7:25:50 PM: ────────────────────────────────────────────────────────────────
7:25:50 PM: ​
7:25:50 PM: ❯ Version
7:25:50 PM: @netlify/build 8.0.0
7:25:50 PM: ​
7:25:50 PM: ❯ Flags
7:25:50 PM: deployId: 5fe3615b485ce800078a0aa9
7:25:50 PM: mode: buildbot
7:25:50 PM: ​
7:25:50 PM: ❯ Current directory
7:25:50 PM: /opt/build/repo
7:25:50 PM: ​
7:25:50 PM: ❯ Config file
7:25:50 PM: /opt/build/repo/netlify.toml
7:25:50 PM: ​
7:25:50 PM: ❯ Context
7:25:50 PM: production
7:25:50 PM: ​
7:25:50 PM: ❯ Loading plugins
7:25:50 PM: - @netlify/plugin-nextjs@1.0.3 from netlify.toml and package.json
7:25:51 PM: ​
7:25:51 PM: ────────────────────────────────────────────────────────────────
7:25:51 PM: 1. onPreBuild command from @netlify/plugin-nextjs
7:25:51 PM: ────────────────────────────────────────────────────────────────
7:25:51 PM: ​
7:25:51 PM: ** Warning: support for Next.js >=10.0.0 is experimental **
7:25:51 PM: ** Adding next.config.js with target set to β€˜serverless’ **
7:25:51 PM: ​
7:25:51 PM: (@netlify/plugin-nextjs onPreBuild completed in 10ms)
7:25:51 PM: ​
7:25:51 PM: ────────────────────────────────────────────────────────────────
7:25:51 PM: 2. build.command from netlify.toml
7:25:51 PM: ────────────────────────────────────────────────────────────────
7:25:51 PM: ​
7:25:51 PM: $ npm run build
7:25:51 PM: > app-hrms@1.0.0 build /opt/build/repo
7:25:51 PM: > next build
7:25:52 PM: Loaded env from /opt/build/repo/.env
7:25:52 PM: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: no-cache | Next.js
7:25:52 PM: info - Creating an optimized production build…
7:26:15 PM: warn - Compiled with warnings
7:26:15 PM: ./node_modules/next/dist/next-server/server/load-components.js
7:26:15 PM: Critical dependency: the request of a dependency is an expression
7:26:15 PM: ./node_modules/next/dist/next-server/server/load-components.js
7:26:15 PM: Critical dependency: the request of a dependency is an expression
7:26:15 PM: ./node_modules/next/dist/next-server/server/require.js
7:26:15 PM: Critical dependency: the request of a dependency is an expression
7:26:15 PM: ./node_modules/next/dist/next-server/server/require.js
7:26:15 PM: Critical dependency: the request of a dependency is an expression
7:26:15 PM: ./node_modules/next/dist/next-server/server/require.js
7:26:15 PM: Critical dependency: the request of a dependency is an expression
7:26:15 PM: ./node_modules/node-fetch/lib/index.js
7:26:15 PM: Module not found: Can’t resolve β€˜encoding’ in β€˜/opt/build/repo/node_modules/node-fetch/lib’
7:26:15 PM: info - Collecting page data…
7:26:16 PM: info - Generating static pages (0/2)
7:26:17 PM: info - Generating static pages (2/2)
7:26:17 PM: info - Finalizing page optimization…
7:26:17 PM: Page Size First Load JS
7:26:17 PM: β”Œ β—‹ / 12.4 kB 75.1 kB
7:26:17 PM: β”œ /_app 0 B 62.7 kB
7:26:17 PM: β”œ β—‹ /404 3.01 kB 65.7 kB
7:26:17 PM: β”œ Ξ» /api/login 0 B 62.7 kB
7:26:17 PM: β”œ Ξ» /api/logout 0 B 62.7 kB
7:26:17 PM: β”” Ξ» /dashboard 4.81 kB 67.5 kB
7:26:17 PM: + First Load JS shared by all 62.7 kB
7:26:17 PM: β”œ chunks/commons.9b549c.js 12.8 kB
7:26:17 PM: β”œ chunks/framework.08d108.js 42.1 kB
7:26:17 PM: β”œ chunks/main.71f255.js 6.55 kB
7:26:17 PM: β”œ chunks/pages/_app.3d4ac7.js 526 B
7:26:17 PM: β”œ chunks/webpack.95c2b2.js 751 B
7:26:17 PM: β”” css/a42914e8e93ff3ff3368.css 4.27 kB
7:26:17 PM: Ξ» (Lambda) server-side renders at runtime (uses getInitialProps or getServerSideProps)
7:26:17 PM: β—‹ (Static) automatically rendered as static HTML (uses no initial props)
7:26:17 PM: ● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)
7:26:17 PM: (ISR) incremental static regeneration (uses revalidate in getStaticProps)
7:26:17 PM: ​
7:26:17 PM: (build.command completed in 25.9s)
7:26:17 PM: ​
7:26:17 PM: ────────────────────────────────────────────────────────────────
7:26:17 PM: 3. onBuild command from @netlify/plugin-nextjs
7:26:17 PM: ────────────────────────────────────────────────────────────────
7:26:17 PM: ​
7:26:17 PM: ** Running Next on Netlify package **
7:26:17 PM: :rocket: Next on Netlify :rocket:
7:26:17 PM: Functions directory: netlify-automatic-functions
7:26:17 PM: Publish directory: /opt/build/repo
7:26:17 PM: Make sure these are set in your netlify.toml file.
7:26:17 PM: :earth_africa: Copying public/ folder to /opt/build/repo
7:26:17 PM: :briefcase: Copying static NextJS assets to /opt/build/repo
7:26:17 PM: :dizzy: Setting up API endpoints as Netlify Functions in netlify-automatic-functions
7:26:17 PM: :dizzy: Setting up pages with getInitialProps as Netlify Functions in netlify-automatic-functions
7:26:17 PM: :dizzy: Setting up pages with getServerSideProps as Netlify Functions in netlify-automatic-functions
7:26:17 PM: :fire: Copying pre-rendered pages with getStaticProps and JSON data to /opt/build/repo
7:26:17 PM: :dizzy: Setting up pages with getStaticProps and fallback: true as Netlify Functions in netlify-automatic-functions
7:26:17 PM: :dizzy: Setting up pages with getStaticProps and revalidation interval as Netlify Functions in netlify-automatic-functions
7:26:17 PM: :fire: Copying pre-rendered pages without props to /opt/build/repo
7:26:17 PM: :twisted_rightwards_arrows: Setting up redirects
7:26:17 PM: ​
7:26:17 PM: (@netlify/plugin-nextjs onBuild completed in 147ms)
7:26:17 PM: ​
7:26:17 PM: ────────────────────────────────────────────────────────────────
7:26:17 PM: 4. Functions bundling
7:26:17 PM: ────────────────────────────────────────────────────────────────
7:26:17 PM: ​
7:26:17 PM: Packaging Functions from netlify-automatic-functions directory:
7:26:17 PM: - next_api_login/next_api_login.js
7:26:17 PM: - next_api_logout/next_api_logout.js
7:26:17 PM: - next_dashboard/next_dashboard.js
7:26:22 PM: ​
7:26:22 PM: ────────────────────────────────────────────────────────────────
7:26:22 PM: Dependencies installation error
7:26:22 PM: ────────────────────────────────────────────────────────────────
7:26:22 PM: ​
7:26:22 PM: Error message
7:26:22 PM: A Netlify Function failed to require one of its dependencies.
7:26:22 PM: If the dependency is a Node module, please make sure it is present in the site’s top-level β€œpackage.json”. If it is a local file instead, please make sure the file exists and its filename is correctly spelled.
7:26:22 PM: ​
7:26:22 PM: In file β€œ/opt/build/repo/netlify-automatic-functions/next_dashboard/next_dashboard.js”
7:26:22 PM: Cannot find module β€˜critters’
7:26:22 PM: Require stack:
7:26:22 PM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/resolve.js
7:26:22 PM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/dependencies.js
7:26:22 PM: - /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
7:26:22 PM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/index.js
7:26:22 PM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/commands/get.js
7:26:22 PM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/main.js
7:26:22 PM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/bin.js
7:26:22 PM: ​
7:26:22 PM: Resolved config
7:26:22 PM: build:
7:26:22 PM: command: npm run build
7:26:22 PM: commandOrigin: config
7:26:22 PM: environment:
7:26:22 PM: - APPLICATION_COOKIE_NAME
7:26:22 PM: - APPLICATION_SECRET
7:26:22 PM: - NEXT_APP_APPLICATION_SECRET
7:26:22 PM: plugins:
7:26:22 PM: - inputs: {}
7:26:22 PM: origin: config
7:26:22 PM: package: β€˜@netlify/plugin-nextjs’
7:26:22 PM: Caching artifacts
7:26:22 PM: Started saving node modules
7:26:22 PM: Finished saving node modules
7:26:22 PM: Started saving build plugins
7:26:22 PM: Finished saving build plugins
7:26:22 PM: Started saving yarn cache
7:26:22 PM: Finished saving yarn cache
7:26:22 PM: Started saving pip cache
7:26:22 PM: Finished saving pip cache
7:26:22 PM: Started saving emacs cask dependencies
7:26:22 PM: Finished saving emacs cask dependencies
7:26:22 PM: Started saving maven dependencies
7:26:22 PM: Finished saving maven dependencies
7:26:22 PM: Started saving boot dependencies
7:26:22 PM: Finished saving boot dependencies
7:26:22 PM: Started saving rust rustup cache
7:26:22 PM: Finished saving rust rustup cache
7:26:22 PM: Started saving rust cargo bin cache
7:26:22 PM: Finished saving rust cargo bin cache
7:26:22 PM: Started saving go dependencies
7:26:22 PM: Finished saving go dependencies
7:26:25 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
7:26:25 PM: Failing build: Failed to build site
7:26:25 PM: Failed during stage β€˜building site’: Build script returned non-zero exit code: 2
7:26:25 PM: Finished processing build request in 1m7.331918145s

Just like the error says, do you have that module in package.json?

I just had the exact same problem. Looks like Next.js’ Webpack config tries to load critters even though it’s not listed as a dependency.

Installing critters as a dev dependency fixed it for me, but changing CSS optimization settings might also work.

1 Like

@hrishikesh and @rbardini

I got the same issue.
Installing of critters as dev dependency fixed for me.

But that looks like hack, not the proper solution. Next-on-netlify package has dependency on critters, not mine code. That is why, I think it should be fixed in Next-on-netlify.

1 Like

Hello all :wave:
You can see an update on this issue here:

TLDR: We published a fix for this to the CLI and build system and have an ongoing discussion on how to avoid such cases in the future.

1 Like

I have similar issues with deployment on Netlify, but with different dependency β€˜encoding’. I discovered that once I added faunadb to my project.

:46:12 PM: ────────────────────────────────────────────────────────────────
3:46:12 PM:   2. Functions bundling                                         
3:46:12 PM: ────────────────────────────────────────────────────────────────
3:46:12 PM: ​
3:46:12 PM: Packaging Functions from lambda directory:
3:46:12 PM:  - currency-rates.js
3:46:12 PM:  - proxy-fetch.js
3:46:12 PM:  - send-mail.js
3:46:14 PM: ​
3:46:14 PM: ────────────────────────────────────────────────────────────────
3:46:14 PM:   Dependencies installation error                               
3:46:14 PM: ────────────────────────────────────────────────────────────────
3:46:14 PM: ​
3:46:14 PM:   Error message
3:46:14 PM:   A Netlify Function failed to require one of its dependencies.
3:46:14 PM:   If the dependency is a Node module, please make sure it is present in the site's top-level "package.json".
  If it is a local file instead, please make sure the file exists and its filename is correctly spelled.
3:46:14 PM: ​
3:46:14 PM:   In file "/opt/build/repo/lambda/currency-rates.js"
3:46:14 PM:   Cannot find module 'encoding'
3:46:14 PM:   Require stack:
3:46:14 PM:   - /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
3:46:14 PM:   - /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
3:46:14 PM:   - /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
3:46:14 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/index.js
3:46:14 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/commands/get.js
3:46:14 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/main.js
3:46:14 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/bin.js
3:46:14 PM: ​
3:46:14 PM:   Resolved config
3:46:14 PM:   build:
3:46:14 PM:     command: npm run build
3:46:14 PM:     commandOrigin: ui
3:46:14 PM:     functions: /opt/build/repo/lambda
3:46:14 PM:     publish: /opt/build/repo/dist

Thanks @bomzj, let’s track this issue under Lambda Functions bundling failed due to non required 'encoding' module Β· Issue #309 Β· netlify/zip-it-and-ship-it Β· GitHub