{"id":"14a596f7ecd9d145","repo":"evanw/esbuild","slug":"cannot-call-initialize-more-than-once","errorCode":null,"errorMessage":"Cannot call \"initialize\" more than once","messagePattern":"Cannot call \"initialize\" more than once","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/npm/node.ts","lineNumber":238,"sourceCode":"    callback: (err, res) => { if (err) throw err; result = res! },\n  }))\n  return result!\n}\n\nexport const stop = () => {\n  if (stopService) stopService()\n  if (workerThreadService) workerThreadService.stop()\n  return Promise.resolve()\n}\n\nlet initializeWasCalled = false\n\nexport let initialize: typeof types.initialize = options => {\n  options = common.validateInitializeOptions(options || {})\n  if (options.wasmURL) throw new Error(`The \"wasmURL\" option only works in the browser`)\n  if (options.wasmModule) throw new Error(`The \"wasmModule\" option only works in the browser`)\n  if (options.worker) throw new Error(`The \"worker\" option only works in the browser`)\n  if (initializeWasCalled) throw new Error('Cannot call \"initialize\" more than once')\n  ensureServiceIsRunning()\n  initializeWasCalled = true\n  return Promise.resolve()\n}\n\ninterface Service {\n  build: typeof types.build\n  context: typeof types.context\n  transform: typeof types.transform\n  formatMessages: typeof types.formatMessages\n  analyzeMetafile: typeof types.analyzeMetafile\n}\n\nlet defaultWD = process.cwd()\nlet longLivedService: Service | undefined\nlet stopService: (() => void) | undefined\n\nlet ensureServiceIsRunning = (): Service => {","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/lib/npm/node.ts#L220-L256","documentation":"Error \"Cannot call \"initialize\" more than once\" thrown in evanw/esbuild.","triggerScenarios":"Thrown at lib/npm/node.ts:238 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call \"initialize\" only once at startup before using the esbuild API","Remove duplicate \"initialize\" calls; subsequent calls are unnecessary once initialization completes"],"exampleFix":"// Call initialize exactly once before any other API usage\nawait esbuild.initialize({});\nawait esbuild.transform(code, { loader: 'ts' });","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}