{"record":{"id":"b8bfdeff500f5e10","repo":"vercel/next.js","slug":"prepare-must-be-called-before-performing-this-op","errorCode":null,"errorMessage":"prepare() must be called before performing this operation","messagePattern":"prepare\\(\\) must be called before performing this operation","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/next/src/server/next.ts","lineNumber":440,"sourceCode":"  }\n}\n\n/** The wrapper server used for `import next from \"next\" (in a custom server)` */\nclass NextCustomServer implements NextWrapperServer {\n  private didWebSocketSetup: boolean = false\n  protected cleanupListeners?: AsyncCallbackSet\n\n  protected init?: ServerInitResult\n\n  public options: NextServerOptions\n\n  constructor(options: NextServerOptions) {\n    this.options = options\n  }\n\n  protected getInit() {\n    if (!this.init) {\n      throw new Error(\n        'prepare() must be called before performing this operation'\n      )\n    }\n    return this.init\n  }\n\n  protected get requestHandler() {\n    return this.getInit().requestHandler\n  }\n  protected get upgradeHandler() {\n    return this.getInit().upgradeHandler\n  }\n  protected get server() {\n    return this.getInit().server\n  }\n\n  get hostname() {\n    return this.options.hostname","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/vercel/next.js/blob/0eb377541648e63402a47b38fee00a8d0ce8f8f1/packages/next/src/server/next.ts#L422-L458","documentation":"Lifecycle invariant on NextCustomServer: an accessor (requestHandler, upgradeHandler, server) that depends on the server's initialization result was touched before prepare() completed. The init field is only populated during prepare, so this indicates a usage-order bug in a custom server integration.","triggerScenarios":"A server operation is invoked before app.prepare() completed.","commonSituations":"Calling request handlers on a custom Next.js server before awaiting prepare().","solutions":["Call await app.prepare() before handling requests with the custom server."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0eb377541648e63402a47b38fee00a8d0ce8f8f1","analyzedAt":"2026-08-19T02:10:13.922Z","contentChangedAt":"2026-08-19T02:10:13.922Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}