{"record":{"id":"b044fadd6311515a","repo":"vercel/next.js","slug":"the-server-has-not-been-instantiated-properly-htt","errorCode":null,"errorMessage":"The server has not been instantiated properly. https://nextjs.org/docs/messages/invalid-server-options","messagePattern":"The server has not been instantiated properly\\. https://nextjs\\.org/docs/messages/invalid-server-options","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/next/src/server/next.ts","lineNumber":659,"sourceCode":"      )\n    }\n  }\n\n  // The package is used as a TypeScript plugin.\n  if (\n    options &&\n    'typescript' in options &&\n    'version' in (options as any).typescript\n  ) {\n    const pluginMod: typeof import('./next-typescript') =\n      require('./next-typescript') as typeof import('./next-typescript')\n    return pluginMod.createTSPlugin(\n      options as any\n    ) as unknown as NextWrapperServer\n  }\n\n  if (options == null) {\n    throw new Error(\n      'The server has not been instantiated properly. https://nextjs.org/docs/messages/invalid-server-options'\n    )\n  }\n\n  if (\n    !('isNextDevCommand' in options) &&\n    process.env.NODE_ENV &&\n    !['production', 'development', 'test'].includes(process.env.NODE_ENV)\n  ) {\n    log.warn(NON_STANDARD_NODE_ENV)\n  }\n\n  if (options.dev && typeof options.dev !== 'boolean') {\n    console.warn(\n      \"Warning: 'dev' is not a boolean which could introduce unexpected behavior. https://nextjs.org/docs/messages/invalid-server-options\"\n    )\n  }\n","sourceCodeStart":641,"sourceCodeEnd":677,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/next.ts#L641-L677","documentation":"Thrown by createServer() when the options argument is null/undefined. Next() requires at least an options object (even an empty one) to instantiate the server; passing nothing leaves it unable to determine dev mode, dir, etc.","triggerScenarios":"Calling `next(null)`, `next(undefined)`, or `require('next')()` with no argument; a variable that was supposed to hold the options object being null due to an earlier assignment bug.","commonSituations":"Programmatic usage where options were conditionally assigned and fell through to undefined; refactoring that dropped the options argument; TypeScript bypass allowing null.","solutions":["Pass an options object, e.g. `next({ dev: process.env.NODE_ENV !== 'production' })`.","Guard the call site: `const app = next(options ?? {})`.","Audit the code path that produces the options variable to ensure it is never null."],"exampleFix":"// before\nconst app = next(maybeUndefined)\n// after\nconst app = next(maybeUndefined ?? { dev: false })","handlingStrategy":"validation","validationCode":"if (options == null) {\n  throw new TypeError('next() requires an options object, e.g. next({ dev: false })')\n}\nconst app = next(options)","typeGuard":"function isValidNextOptions(o: unknown): o is Record<string, unknown> {\n  return o != null && typeof o === 'object'\n}","tryCatchPattern":null,"preventionTips":["Always pass an explicit options object to next(), at minimum { dev }.","Default options with a fallback: next(options ?? { dev: false }).","Trace the variable supplying options to ensure it is never null/undefined."],"tags":["server","config","startup","programmatic"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}