Dependencies installation error Cannot find module '../webpack-runtime.js'

Hi there,

As per title I am having problems to deploy a nextjs website on netlify.

The error is :

Dependencies installation error

Cannot find module ‘…/webpack-runtime.js’

Before this error I had a similar one that could not find the module webpack, so I installed webpack as dependancies and now it cannot find webpack-runtime.js

I will attach the full log but yes This is the only error that I can’t solve.

I will appreciate the time that you will spend to help me out.

10:15:15 PM: Build ready to start
10:15:16 PM: build-image version: 8925038cf853b22d6397cdcb9904ac88b66bb383 (focal)
10:15:16 PM: build-image tag: v4.5.0
10:15:16 PM: buildbot version: 0e1298c157b10f24ae5c9a9af08df22d0babb90a
10:15:17 PM: Fetching cached dependencies
10:15:17 PM: Failed to fetch cache, continuing with build
10:15:17 PM: Starting to prepare the repo for build
10:15:17 PM: No cached dependencies found. Cloning fresh repo
10:15:17 PM: git clone https://github.com/MikysIta/MIkysItalianRestaurant
10:15:18 PM: Preparing Git Reference refs/heads/main
10:15:18 PM: Parsing package.json dependencies
10:15:19 PM: Starting build script
10:15:19 PM: Installing dependencies
10:15:19 PM: Python version set to 2.7
10:15:19 PM: v16.13.0 is already installed.
10:15:20 PM: Now using node v16.13.0 (npm v8.1.0)
10:15:20 PM: Started restoring cached build plugins
10:15:20 PM: Finished restoring cached build plugins
10:15:20 PM: Attempting ruby version 2.7.2, read from environment
10:15:22 PM: Using ruby version 2.7.2
10:15:22 PM: Using PHP version 8.0
10:15:22 PM: Started restoring cached node modules
10:15:22 PM: Finished restoring cached node modules
10:15:22 PM: Installing NPM modules using NPM version 8.1.0
10:15:29 PM: npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
10:15:30 PM: npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
10:15:32 PM: npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
10:15:36 PM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
10:15:44 PM: added 779 packages, and audited 780 packages in 21s
10:15:44 PM: 87 packages are looking for funding
10:15:44 PM:   run `npm fund` for details
10:15:44 PM: 10 vulnerabilities (5 moderate, 5 high)
10:15:44 PM: To address issues that do not require attention, run:
10:15:44 PM:   npm audit fix
10:15:44 PM: To address all issues (including breaking changes), run:
10:15:44 PM:   npm audit fix --force
10:15:44 PM: Run `npm audit` for details.
10:15:44 PM: NPM modules installed
10:15:44 PM: Started restoring cached go cache
10:15:44 PM: Finished restoring cached go cache
10:15:44 PM: go version go1.16.5 linux/amd64
10:15:44 PM: go version go1.16.5 linux/amd64
10:15:44 PM: Installing missing commands
10:15:44 PM: Verify run directory
10:15:46 PM: ​
10:15:46 PM: ────────────────────────────────────────────────────────────────
10:15:46 PM:   Netlify Build                                                 
10:15:46 PM: ────────────────────────────────────────────────────────────────
10:15:46 PM: ​
10:15:46 PM: ❯ Version
10:15:46 PM:   @netlify/build 18.22.0
10:15:46 PM: ​
10:15:46 PM: ❯ Flags
10:15:46 PM:   baseRelDir: true
10:15:46 PM:   buildId: 61950e726e9b04000731e9a7
10:15:46 PM:   deployId: 61950e726e9b04000731e9a9
10:15:46 PM: ​
10:15:46 PM: ❯ Current directory
10:15:46 PM:   /opt/build/repo
10:15:46 PM: ​
10:15:46 PM: ❯ Config file
10:15:46 PM:   No config file was defined: using default values.
10:15:46 PM: ​
10:15:46 PM: ❯ Context
10:15:46 PM:   production
10:15:46 PM: ​
10:15:46 PM: ❯ Installing plugins
10:15:46 PM:    - @netlify/plugin-nextjs@3.9.2
10:15:56 PM: ​
10:15:56 PM: ❯ Loading plugins
10:15:56 PM:    - @netlify/plugin-nextjs@3.9.2 from Netlify app
10:15:56 PM: ​
10:15:56 PM: ────────────────────────────────────────────────────────────────
10:15:56 PM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
10:15:56 PM: ────────────────────────────────────────────────────────────────
10:15:56 PM: ​
10:15:56 PM: Using Next.js 12.0.1
10:15:56 PM: Warning: support for Next.js >=11.1.0 is experimental
10:15:56 PM: warn  - The `target` config is deprecated and will be removed in a future version.
10:15:56 PM: See more info here https://nextjs.org/docs/messages/deprecated-target-config
10:15:56 PM: warn  - SWC minify beta enabled. https://nextjs.org/docs/messages/swc-minify-enabled
10:15:57 PM: No Next.js cache to restore.
10:15:57 PM: ​
10:15:57 PM: (@netlify/plugin-nextjs onPreBuild completed in 482ms)
10:15:57 PM: ​
10:15:57 PM: ────────────────────────────────────────────────────────────────
10:15:57 PM:   2. Build command from Netlify app                             
10:15:57 PM: ────────────────────────────────────────────────────────────────
10:15:57 PM: ​
10:15:57 PM: $ CI= npm run build
10:15:57 PM: > mikys-restautant@0.1.0 build
10:15:57 PM: > next build
10:15:58 PM: warn  - The `target` config is deprecated and will be removed in a future version.
10:15:58 PM: See more info here https://nextjs.org/docs/messages/deprecated-target-config
10:15:58 PM: warn  - SWC minify beta enabled. https://nextjs.org/docs/messages/swc-minify-enabled
10:15:58 PM: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
10:15:58 PM: info  - Checking validity of types...
10:15:58 PM: warn  - No ESLint configuration detected. Run next lint to begin setup
10:15:58 PM: info  - Creating an optimized production build...
10:16:10 PM: info  - Compiled successfully
10:16:10 PM: info  - Collecting page data...
10:16:14 PM: info  - Generating static pages (0/3)
10:16:15 PM: info  - Generating static pages (3/3)
10:16:16 PM: info  - Finalizing page optimization...
10:16:16 PM: Page                                       Size     First Load JS
10:16:16 PM: ┌ ● / (ISR: 60 Seconds) (826 ms)           12.2 kB         153 kB
10:16:16 PM: ├   └ css/98b107dd0aef7aa1.css             3.58 kB
10:16:16 PM: ├   /_app                                  0 B             141 kB
10:16:16 PM: ├ ○ /404                                   180 B           141 kB
10:16:16 PM: └ λ /api/hello                             0 B             141 kB
10:16:16 PM: + First Load JS shared by all              141 kB
10:16:16 PM:   ├ chunks/framework-93dc06fa7fcdddfb.js   42 kB
10:16:16 PM:   ├ chunks/main-d759bdc14c60e417.js        27.9 kB
10:16:16 PM:   ├ chunks/pages/_app-6ec160765553d6be.js  70.2 kB
10:16:16 PM:   ├ chunks/webpack-29f4e7141b68b4d4.js     831 B
10:16:16 PM:   └ css/c16a101db0bb099b.css               1.39 kB
10:16:16 PM: λ  (Lambda)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
10:16:16 PM: ○  (Static)  automatically rendered as static HTML (uses no initial props)
10:16:16 PM: ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
10:16:16 PM:    (ISR)     incremental static regeneration (uses revalidate in getStaticProps)
10:16:16 PM: ​
10:16:16 PM: (build.command completed in 19s)
10:16:16 PM: ​
10:16:16 PM: ────────────────────────────────────────────────────────────────
10:16:16 PM:   3. @netlify/plugin-nextjs (onBuild event)                     
10:16:16 PM: ────────────────────────────────────────────────────────────────
10:16:16 PM: ​
10:16:16 PM: Detected Next.js site. Copying files...
10:16:16 PM: ** Running Next on Netlify package **
10:16:16 PM: 🚀 Next on Netlify 🚀
10:16:16 PM: 🌍️ Copying public folder to /opt/build/repo/out
10:16:16 PM: 💼 Copying static NextJS assets to /opt/build/repo/out
10:16:16 PM: 💫 Setting up API endpoints as Netlify Functions in /opt/build/repo/.netlify/functions-internal
10:16:16 PM: 💫 Setting up pages with getInitialProps as Netlify Functions in /opt/build/repo/.netlify/functions-internal
10:16:16 PM: 💫 Setting up pages with getServerSideProps as Netlify Functions in /opt/build/repo/.netlify/functions-internal
10:16:16 PM: 🔥 Copying pre-rendered pages with getStaticProps and JSON data to /opt/build/repo/out
10:16:16 PM: 💫 Setting up pages with getStaticProps and fallback: true as Netlify Functions in /opt/build/repo/.netlify/functions-internal
10:16:16 PM: 💫 Setting up pages with getStaticProps and revalidation interval as Netlify Functions in /opt/build/repo/.netlify/functions-internal
10:16:16 PM: Warning: It looks like you're using the 'revalidate' flag in one of your Next.js pages.  Please read our docs about ISR on Netlify: https://ntl.fyi/next-isr-info🔥 Copying pre-rendered pages without props to /opt/build/repo/out
10:16:16 PM: Building 3 pages
10:16:16 PM: 🔀 Setting up redirects
10:16:16 PM: Warning: It looks like you're using the 'revalidate' flag in one of your Next.js pages.  Please read our docs about ISR on Netlify: https://ntl.fyi/next-isr-info🔀 Setting up headers
10:16:16 PM: ✅ Success! All done!
10:16:16 PM: Netlify configuration property "functions.*.included_files" value changed to [
10:16:16 PM:   '!node_modules/@next/swc-*/**/*',
10:16:16 PM:   '!node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/**/*'
10:16:16 PM: ].
10:16:16 PM: ​
10:16:16 PM: (@netlify/plugin-nextjs onBuild completed in 83ms)
10:16:16 PM: ​
10:16:16 PM: ────────────────────────────────────────────────────────────────
10:16:16 PM:   4. Functions bundling                                         
10:16:16 PM: ────────────────────────────────────────────────────────────────
10:16:16 PM: ​
10:16:16 PM: Packaging Functions from .netlify/functions-internal directory:
10:16:16 PM:  - next_api_hello/next_api_hello.js
10:16:16 PM:  - next_image/next_image.js
10:16:16 PM:  - next_index/next_index.js
10:16:16 PM: ​
10:16:19 PM: ​
10:16:19 PM: ────────────────────────────────────────────────────────────────
10:16:19 PM:   Dependencies installation error                               
10:16:19 PM: ────────────────────────────────────────────────────────────────
10:16:19 PM: ​
10:16:19 PM:   Error message
10:16:19 PM:   A Netlify Function failed to require one of its dependencies.
10:16:19 PM:   Please make sure it is present in the site's top-level "package.json".​
10:16:19 PM:   In file "/opt/build/repo/.netlify/functions-internal/next_index/next_index.js"
10:16:19 PM:   Cannot find module '../webpack-runtime.js' from '/opt/build/repo/.netlify/functions-internal/next_index/nextPage/pages'
10:16:19 PM: ​
10:16:19 PM:   Resolved config
10:16:19 PM:   build:
10:16:19 PM:     command: CI= npm run build
10:16:19 PM:     commandOrigin: ui
10:16:19 PM:     environment:
10:16:19 PM:       - NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN
10:16:19 PM:       - NEXT_PUBLIC_CONTENTFUL_SPACE_ID
10:16:19 PM:       - NEXT_PUBLIC_USER_ID_EMAILJS
10:16:19 PM:     publish: /opt/build/repo/out
10:16:19 PM:     publishOrigin: ui
10:16:19 PM:   functions:
10:16:19 PM:     '*':
10:16:19 PM:       included_files:
10:16:19 PM:         - '!node_modules/@next/swc-*/**/*'
10:16:19 PM:         - '!node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/**/*'
10:16:19 PM:   headers:
10:16:33 PM:     - for: /_next/static/chunks/*      values:        cache-control: public, max-age=31536000, immutable  plugins:    - inputs: {}      origin: ui      package: '@netlify/plugin-nextjs'  redirects:    - from: /      status: 200      to: /.netlify/functions/next_index    - from: /_next/data/_OtedoIJ41GdpCNNGQl3N/index.json      status: 200      to: /.netlify/functions/next_index    - from: /api/hello      status: 200      to: /.netlify/functions/next_api_hello    - force: true      from: /_next/image*      query:        q: ':quality'        url: ':url'        w: ':width'      status: 301      to: /nextimg/:url/:width/:quality    - from: /nextimg/*      status: 200      to: /.netlify/functions/next_imageCaching artifacts
10:16:33 PM: Started saving node modules
10:16:33 PM: Finished saving node modules
10:16:33 PM: Started saving build plugins
10:16:33 PM: Finished saving build plugins
10:16:33 PM: Started saving pip cache
10:16:33 PM: Finished saving pip cache
10:16:33 PM: Started saving emacs cask dependencies
10:16:33 PM: Finished saving emacs cask dependencies
10:16:33 PM: Started saving maven dependencies
10:16:33 PM: Finished saving maven dependencies
10:16:33 PM: Started saving boot dependencies
10:16:33 PM: Finished saving boot dependencies
10:16:33 PM: Started saving rust rustup cache
10:16:33 PM: Finished saving rust rustup cache
10:16:33 PM: Started saving go dependencies
10:16:33 PM: Finished saving go dependencies
10:16:35 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
10:16:35 PM: Creating deploy upload records
10:16:35 PM: Failing build: Failed to build site
10:16:35 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
10:16:35 PM: Finished processing build request in 1m18.837271965s

Thank you

Related:

Thank you hrishikesh, I solved the issues installing the plugin in my next js website and changin the publish to .next adding also a netlify.toml file.

1 Like

Could you specify what exactly you have done to resolve this issue. I have the same problem but can’t get it to work :confused:

Hi there, @superwolko :wave:

Building off of @MikysIta, there are instructions at the next.js beta discussion for how to install the plugin correctly. Please confirm that you are using the latest beta release and have it installed correctly.

If you are still encountering issues after that, please share your netlify site, your most recent build log, and your public project repo so we can look into this further.

Hey Superwolko, sry but I just saw the message now,
So what I did and worked for me was, update node js, install with npm the netlify plugin for next js,
I added a netlify.toml file in the my folder structure of the website

[build]
command = "npm run build"
publish = ".next"

[functions]
  included_files = [".next/*.json"]

and in my netlify account -->(select your website , build and deploy, build settings,edit build settins) I changed the publish directory to .next

Hope it wil help you unless you already solved the issue