{"record":{"id":"fdbf4a13221a7b97","repo":"cypress-io/cypress","slug":"failed-to-load-next-dist-server-config-with-erro","errorCode":null,"errorMessage":"Failed to load \"next/dist/server/config\" with error: ${e.message ?? e}","messagePattern":"Failed to load \"next/dist/server/config\" with error: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"npm/webpack-dev-server/src/helpers/nextHandler.ts","lineNumber":57,"sourceCode":"\n  // Starting with Next.js 16.0.3, we need to proactively install SWC bindings\n  // See: https://github.com/vercel/next.js/pull/85787\n  try {\n    const installBindingsPath = require.resolve('next/dist/build/swc/install-bindings', resolvePaths)\n    const { installBindings } = require(installBindingsPath)\n\n    await installBindings()\n  } catch (e: any) {\n    // installBindings doesn't exist in Next.js < 16.0.3, which is fine\n    debug('installBindings not available (Next.js < 16.0.3): %s', e.message ?? e)\n  }\n\n  try {\n    const loadConfigPath = require.resolve('next/dist/server/config', resolvePaths)\n\n    packages.loadConfig = require(loadConfigPath).default\n  } catch (e: any) {\n    throw new Error(`Failed to load \"next/dist/server/config\" with error: ${e.message ?? e}`)\n  }\n\n  try {\n    const getNextJsBaseWebpackConfigPath = require.resolve('next/dist/build/webpack-config', resolvePaths)\n\n    packages.getNextJsBaseWebpackConfig = require(getNextJsBaseWebpackConfigPath).default\n  } catch (e: any) {\n    throw new Error(`Failed to load \"next/dist/build/webpack-config\" with error: ${ e.message ?? e}`)\n  }\n\n  try {\n    const loadJsConfigPath = require.resolve('next/dist/build/load-jsconfig', resolvePaths)\n\n    packages.nextLoadJsConfig = require(loadJsConfigPath).default\n  } catch (e: any) {\n    throw new Error(`Failed to load \"next/dist/build/load-jsconfig\" with error: ${ e.message ?? e}`)\n  }\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/cypress-io/cypress/blob/0d85fdc91230885bca0a91df278312800a48b727/npm/webpack-dev-server/src/helpers/nextHandler.ts#L39-L75","documentation":"Thrown by the Next.js handler when require.resolve('next/dist/server/config', resolvePaths) fails or the subsequent require fails to read the default export. This module is the entrypoint Cypress uses to load the user's next.config.js (loadConfig). Without it Cypress cannot obtain the Next.js webpack config to merge with its own. The error chains the underlying message via e.message ?? e.","triggerScenarios":"Running Cypress component tests against a Next.js project where the `next` package is not installed, is installed in a location outside resolvePaths, or is a version whose internal layout moved next/dist/server/config.js. Also thrown if the resolved file exists but throws on require (syntax error, missing transitive dep).","commonSituations":"Missing `next` dependency, yarn/npm hoisting keeping `next` outside the resolution path, a Next.js canary or major version where the internal file layout changed, or a broken node_modules from an interrupted install.","solutions":["Install next at a supported version: `npm install --save-dev next`.","Run `npm ls next` to confirm it is resolvable from the project root and not duplicated.","If using a custom resolvePaths in the devServer config, ensure it points at a directory whose node_modules contains `next`.","Clear node_modules and the package manager lockfile, then reinstall if the install was interrupted."],"exampleFix":"// before\n// package.json devDependencies missing next\n// after\n{\n  \"devDependencies\": {\n    \"next\": \"^14.2.0\"\n  }\n}","handlingStrategy":"validation","validationCode":"function assertNextResolvable (resolvePaths: string[]) {\n  try {\n    require.resolve('next/dist/server/config', { paths: resolvePaths })\n  } catch (e: any) {\n    throw new Error(`Install or repair 'next' before Cypress CT: ${e.message}`)\n  }\n}","typeGuard":"function isNextInstalled (resolvePaths: string[]): boolean {\n  try { require.resolve('next/dist/server/config', { paths: resolvePaths }); return true }\n  catch { return false }\n}","tryCatchPattern":"try {\n  await loadNextHandler(resolvePaths)\n} catch (e) {\n  if (/Failed to load \"next\\/dist\\/server\\/config\"/.test(e.message)) {\n    console.error('Next.js is missing or broken — run `npm install next`.')\n  }\n  throw e\n}","preventionTips":["Pin a stable Next.js version supported by your Cypress release.","Run npm ls next to detect duplicates before testing.","Validate resolution in a pretest script."],"tags":["nextjs","dependency-resolution","dev-server"],"backgroundTag":null,"analyzedSha":"0d85fdc91230885bca0a91df278312800a48b727","analyzedAt":"2026-08-12T16:24:28.056Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}