{"id":"2e3b643fb6381e29","repo":"evanw/esbuild","slug":"the-service-is-no-longer-running-closedata-reason","errorCode":null,"errorMessage":"The service is no longer running${closeData.reason}","messagePattern":"The service is no longer running(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/shared/common.ts","lineNumber":567,"sourceCode":"    responseCallbacks = {}\n  }\n\n  let sendRequest = <Req, Res>(refs: Refs | null, value: Req, callback: (error: string | null, response: Res | null) => void): void => {\n    if (closeData.didClose) return callback('The service is no longer running' + closeData.reason, null)\n    let id = nextRequestID++\n    responseCallbacks[id] = (error, response) => {\n      try {\n        callback(error, response as any)\n      } finally {\n        if (refs) refs.unref() // Do this after the callback so the callback can extend the lifetime if needed\n      }\n    }\n    if (refs) refs.ref()\n    streamIn.writeToStdin(protocol.encodePacket({ id, isRequest: true, value: value as any }))\n  }\n\n  let sendResponse = (id: number, value: protocol.Value): void => {\n    if (closeData.didClose) throw new Error('The service is no longer running' + closeData.reason)\n    streamIn.writeToStdin(protocol.encodePacket({ id, isRequest: false, value }))\n  }\n\n  let handleRequest = async (id: number, request: any) => {\n    // Catch exceptions in the code below so they get passed to the caller\n    try {\n      if (request.command === 'ping') {\n        sendResponse(id, {})\n        return\n      }\n\n      if (typeof request.key === 'number') {\n        const requestCallbacks = requestCallbacksByKey[request.key]\n        if (!requestCallbacks) {\n          // Ignore invalid commands for old builds that no longer exist.\n          // This can happen when \"context.cancel\" and \"context.dispose\"\n          // is called while esbuild is processing many files in parallel.\n          // See https://github.com/evanw/esbuild/issues/3318 for details.","sourceCodeStart":549,"sourceCodeEnd":585,"githubUrl":"https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/lib/shared/common.ts#L549-L585","documentation":"Error \"The service is no longer running${closeData.reason}\" thrown in evanw/esbuild.","triggerScenarios":"Thrown at lib/shared/common.ts:567 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Create a new esbuild context/service; the previous one was stopped and cannot be reused","Avoid calling stop() before you are done using the service, and recreate it if needed"],"exampleFix":"const ctx = await esbuild.context(options);\n// use ctx...\nawait ctx.dispose(); // only when completely done","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}