{"record":{"id":"ca37eaacbd0490e9","repo":"evanw/esbuild","slug":"the-analyzemetafilesync-api-only-works-in-node","errorCode":null,"errorMessage":"The \"analyzeMetafileSync\" API only works in node","messagePattern":"The \"analyzeMetafileSync\" API only works in node","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/npm/browser.ts","lineNumber":45,"sourceCode":"  ensureServiceIsRunning().formatMessages(messages, options)\n\nexport const analyzeMetafile: typeof types.analyzeMetafile = (metafile, options) =>\n  ensureServiceIsRunning().analyzeMetafile(metafile, options)\n\nexport const buildSync: typeof types.buildSync = () => {\n  throw new Error(`The \"buildSync\" API only works in node`)\n}\n\nexport const transformSync: typeof types.transformSync = () => {\n  throw new Error(`The \"transformSync\" API only works in node`)\n}\n\nexport const formatMessagesSync: typeof types.formatMessagesSync = () => {\n  throw new Error(`The \"formatMessagesSync\" API only works in node`)\n}\n\nexport const analyzeMetafileSync: typeof types.analyzeMetafileSync = () => {\n  throw new Error(`The \"analyzeMetafileSync\" API only works in node`)\n}\n\nexport const stop = () => {\n  if (stopService) stopService()\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 initializePromise: Promise<void> | undefined\nlet stopService: (() => void) | undefined\nlet longLivedService: Service | undefined","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/lib/npm/browser.ts#L27-L63","documentation":"The browser entry of esbuild (lib/npm/browser.ts) defines analyzeMetafileSync as a stub that always throws. Metafile analysis in the browser goes through the async WebAssembly service, so no synchronous form is offered.","triggerScenarios":"Application code calls esbuild.analyzeMetafileSync(metafile, options) while the active module is the browser build (esbuild-wasm or the package 'browser' field).","commonSituations":"Bundle-size analysis dashboards running in the browser that reused node sample code; build-report tooling shared between node and web.","solutions":["Use esbuild.analyzeMetafile(...) and await the returned promise.","Perform the analysis ahead of time in a node build step and ship the result.","Use the native esbuild package under node if a synchronous call is mandatory."],"exampleFix":"// before\nconst report = esbuild.analyzeMetafileSync(metafile)\n\n// after\nconst report = await esbuild.analyzeMetafile(metafile)","handlingStrategy":"validation","validationCode":"// Choose the async analyze API in browser-capable code.\nconst isBrowserBuild =\n  typeof window !== 'undefined' && typeof window.document !== 'undefined'\n\nconst report = isBrowserBuild\n  ? await esbuild.analyzeMetafile(metafile)\n  : esbuild.analyzeMetafileSync(metafile)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run metafile analysis asynchronously in shared code.","Compute the analysis during a node build and persist the result for the browser.","Do not call analyzeMetafileSync from modules that resolve to the browser entry."],"tags":["browser","sync","async","platform","wasm"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}