cypress-io/cypress · error · Error

Failed to load "next/dist/build/webpack-config" with error:

Error message

Failed to load "next/dist/build/webpack-config" with error: ${ e.message ?? e}

What it means

Thrown by the Next.js handler when require.resolve('next/dist/build/webpack-config', resolvePaths) fails or the default export cannot be loaded. Cypress uses getNextJsBaseWebpackConfig to obtain the base webpack configuration Next.js itself produces, then merges Cypress-specific entries/loaders into it. Loss of this module means Cypress cannot reuse Next's compiled webpack rules.

Source

Thrown at npm/webpack-dev-server/src/helpers/nextHandler.ts:65

  } catch (e: any) {
    // installBindings doesn't exist in Next.js < 16.0.3, which is fine
    debug('installBindings not available (Next.js < 16.0.3): %s', e.message ?? e)
  }

  try {
    const loadConfigPath = require.resolve('next/dist/server/config', resolvePaths)

    packages.loadConfig = require(loadConfigPath).default
  } catch (e: any) {
    throw new Error(`Failed to load "next/dist/server/config" with error: ${e.message ?? e}`)
  }

  try {
    const getNextJsBaseWebpackConfigPath = require.resolve('next/dist/build/webpack-config', resolvePaths)

    packages.getNextJsBaseWebpackConfig = require(getNextJsBaseWebpackConfigPath).default
  } catch (e: any) {
    throw new Error(`Failed to load "next/dist/build/webpack-config" with error: ${ e.message ?? e}`)
  }

  try {
    const loadJsConfigPath = require.resolve('next/dist/build/load-jsconfig', resolvePaths)

    packages.nextLoadJsConfig = require(loadJsConfigPath).default
  } catch (e: any) {
    throw new Error(`Failed to load "next/dist/build/load-jsconfig" with error: ${ e.message ?? e}`)
  }

  // Does not exist prior to Next 13.
  try {
    const getUtilsPath = require.resolve('next/dist/build/utils', resolvePaths)

    packages.getSupportedBrowsers = require(getUtilsPath).getSupportedBrowsers ?? (() => Promise.resolve([]))
  } catch (e: any) {
    throw new Error(`Failed to load "next/dist/build/utils" with error: ${ e.message ?? e}`)
  }

View on GitHub (pinned to 0d85fdc912)

Solutions

  1. Pin to a stable, supported Next.js version (avoid canary if the file is missing).
  2. Reinstall node_modules to repair a partial Next.js install: `rm -rf node_modules && npm install`.
  3. Check Next.js release notes for the installed version; if webpack-config moved, downgrade/upgrade to a Cypress-supported range.
  4. Verify `require.resolve('next/dist/build/webpack-config')` succeeds from your project root in a plain Node REPL.

Example fix

# diagnostic
node -e "console.log(require.resolve('next/dist/build/webpack-config'))"
# if it throws, reinstall next at a known-good version
npm install --save-dev next@14.2.0
Defensive patterns

Strategy: validation

Validate before calling

function assertNextWebpackConfig (resolvePaths: string[]) {
  require.resolve('next/dist/build/webpack-config', { paths: resolvePaths })
}

Type guard

function isNextWebpackConfigResolvable (resolvePaths: string[]): boolean {
  try { require.resolve('next/dist/build/webpack-config', { paths: resolvePaths }); return true }
  catch { return false }
}

Prevention

When it happens

Trigger: Next.js is installed but the dist/build/webpack-config file is missing (rare internal layout change), or the require throws because of a missing transitive dependency of the webpack-config module. Distinct from error 43 because the config-loading step already succeeded before this one runs.

Common situations: Next.js major version change where build/webpack-config was refactored (e.g. moving to turbopack-only layouts), partial install, or a Next.js canary build that omitted the file.

Related errors


AI-assisted analysis of cypress-io/cypress@0d85fdc912 (2026-08-12). Data as JSON: /api/errors/4b0bb6ca77bd07b6. Report an issue: GitHub.