evanw/esbuild · error · Error
Cannot call "initialize" more than once
Error message
Cannot call "initialize" more than once
What it means
Error "Cannot call "initialize" more than once" thrown in evanw/esbuild.
Source
Thrown at lib/npm/node.ts:238
callback: (err, res) => { if (err) throw err; result = res! },
}))
return result!
}
export const stop = () => {
if (stopService) stopService()
if (workerThreadService) workerThreadService.stop()
return Promise.resolve()
}
let initializeWasCalled = false
export let initialize: typeof types.initialize = options => {
options = common.validateInitializeOptions(options || {})
if (options.wasmURL) throw new Error(`The "wasmURL" option only works in the browser`)
if (options.wasmModule) throw new Error(`The "wasmModule" option only works in the browser`)
if (options.worker) throw new Error(`The "worker" option only works in the browser`)
if (initializeWasCalled) throw new Error('Cannot call "initialize" more than once')
ensureServiceIsRunning()
initializeWasCalled = true
return Promise.resolve()
}
interface Service {
build: typeof types.build
context: typeof types.context
transform: typeof types.transform
formatMessages: typeof types.formatMessages
analyzeMetafile: typeof types.analyzeMetafile
}
let defaultWD = process.cwd()
let longLivedService: Service | undefined
let stopService: (() => void) | undefined
let ensureServiceIsRunning = (): Service => {View on GitHub (pinned to 6ff1d8b0d8)
Solutions
- Call "initialize" only once at startup before using the esbuild API
- Remove duplicate "initialize" calls; subsequent calls are unnecessary once initialization completes
Example fix
// Call initialize exactly once before any other API usage
await esbuild.initialize({});
await esbuild.transform(code, { loader: 'ts' }); When it happens
Trigger: Thrown at lib/npm/node.ts:238 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of evanw/esbuild@6ff1d8b0d8 (2026-08-03).
Data as JSON: /data/errors/14a596f7ecd9d145.json.
Report an issue: GitHub.