cypress-io/cypress · error · Error

Failed to load "next/dist/build/utils" with error: ${ e.mess

Error message

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

What it means

Thrown when require.resolve('next/dist/build/utils', resolvePaths) fails. Cypress reads getSupportedBrowsers from this module to know which browsers Next targets during compilation; if the file is missing the handler has no list to work from. The inline comment 'Does not exist prior to Next 13' acknowledges the file is version-dependent, but the code does not provide a fallback at the require layer — it only falls back if getSupportedBrowsers is absent after a successful load.

Source

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

  } 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}`)
  }

  return packages
}

/**
 * Types for `getNextJsBaseWebpackConfig` based on version:
 * - v14.0.0, v15.0.0, and v16.0.0
  [
    dir: string,
    options:  {
      buildId: string
      encryptionKey: string
      config: NextConfigComplete
      compilerType: CompilerNameValues
      dev?: boolean
      entrypoints: webpack.EntryObject
      isDevFallback?: boolean

View on GitHub (pinned to 0d85fdc912)

Solutions

  1. Upgrade to Next.js 13 or newer.
  2. Reinstall node_modules to repair a partial Next.js install.
  3. Confirm the file exists: `ls node_modules/next/dist/build/utils.js`.
  4. If you must remain on Next 12, pin @cypress/webpack-dev-server to a version compatible with that Next line.

Example fix

# verify
ls node_modules/next/dist/build/utils.js
# repair
rm -rf node_modules package-lock.json && npm install
Defensive patterns

Strategy: validation

Validate before calling

function assertNextBuildUtils (resolvePaths: string[]) {
  try {
    require.resolve('next/dist/build/utils', { paths: resolvePaths })
  } catch {
    throw new Error('next/dist/build/utils missing — upgrade Next.js to >= 13')
  }
}

Type guard

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

Prevention

When it happens

Trigger: Using Next.js < 13 (where next/dist/build/utils either does not exist or has a different shape), or a broken/partial install where the file is missing in a modern Next version.

Common situations: Stale Next.js 12 install, manually trimmed node_modules, or a Next.js distribution that does not ship dist/build/utils.js.

Related errors


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