{"record":{"id":"e6b139c0f2ea6ab0","repo":"oven-sh/bun","slug":"errors-in-entrypoint-errors-map-x-x-1-j","errorCode":null,"errorMessage":"Errors in ${entrypoint}:\n${errors.map(x => x[1]).join(\"\\n\")}","messagePattern":"Errors in (.+?):\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/bundle-modules.ts","lineNumber":279,"sourceCode":"        throw new Error(`Builtin Bundler: do not use import.meta.require() (in ${file_path}))`);\n      })\n      .replace(/return \\$\\nexport /, \"return\")\n      .replace(/__intrinsic__/g, \"@\")\n      .replace(/__no_intrinsic__/g, \"\") + \"\\n\";\n  captured = captured.replace(\n    /function\\s*\\(.*?\\)\\s*{/,\n    '$&\"use strict\";' +\n      (usesDebug\n        ? createLogClientJS(\n            file_path.replace(\".js\", \"\"),\n            idToPublicSpecifierOrEnumName(file_path).replace(/^node:|^bun:/, \"\"),\n          )\n        : \"\") +\n      (usesAssert ? createAssertClientJS(idToPublicSpecifierOrEnumName(file_path).replace(/^node:|^bun:/, \"\")) : \"\"),\n  );\n  const errors = [...captured.matchAll(/@bundleError\\((.*)\\)/g)];\n  if (errors.length) {\n    throw new Error(`Errors in ${entrypoint}:\\n${errors.map(x => x[1]).join(\"\\n\")}`);\n  }\n\n  const outputPath = path.join(JS_DIR, file_path);\n  fs.mkdirSync(path.dirname(outputPath), { recursive: true });\n  fs.writeFileSync(outputPath, captured);\n  outputs.set(file_path.replace(\".js\", \"\"), captured);\n}\n\nmark(\"Postprocesss modules\");\n\n/**\n * Physical layout order for the module-source blob: DFS post-order over the\n * static require() graph, so each module sits contiguous with its transitive\n * dependencies. Loading any builtin then reads one contiguous run of pages\n * instead of touching sources scattered across the blob. Roots are visited in\n * a fixed order (the popular entry modules first) so the layout is\n * deterministic; the graph over-approximates lazy requires, which only makes\n * neighbours of things that *might* co-load — free for layout.","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/bundle-modules.ts#L261-L297","documentation":"After bundling a builtin module, the codegen scans the captured output for @bundleError(...) markers. These markers come from the $bundleError(...) compile-time intrinsic used in src/js sources (e.g. src/js/node/os.ts uses $bundleError(\"TODO: endianness\")) to flag branches that must be eliminated during bundling. If a marker survives into the output, some branch of the module was left unimplemented or unreachable-code elimination could not prove it dead, so the build aborts listing every surviving marker.","triggerScenarios":"Adding a $bundleError(...) to a new branch of a builtin module and that branch survives bundling (the surrounding condition is not statically resolvable at bundle time); or editing conditional logic in a module like src/js/node/os.ts so a previously dead $bundleError branch becomes reachable.","commonSituations":"Contributors stubbing out a platform-specific case with $bundleError as a placeholder; build-time defines changing so a previously eliminated branch no longer constant-folds.","solutions":["Read the listed marker messages — they are exactly the $bundleError strings that survived (e.g. 'TODO: endianness') and identify the unimplemented case","Implement the missing branch so $bundleError becomes unreachable, or make its condition statically known to the bundler","Re-run the codegen to confirm no markers remain in the module output"],"exampleFix":"// before (builtin module)\nprocess.arch === \"x64\" ? \"x64\" : $bundleError(\"TODO: arch\");\n\n// after\nprocess.arch === \"x64\" ? \"x64\" : \"unknown\";","handlingStrategy":"validation","validationCode":"// scan builtin sources for $bundleError placeholders before building\nimport { Glob } from \"bun\";\nfor (const f of new Glob(\"src/js/**/*.{ts,js}\").scanSync(\".\")) {\n  const text = await Bun.file(f).text();\n  if (text.includes(\"$bundleError\")) {\n    console.warn(`${f} still contains $bundleError — ensure every branch is bundle-time resolvable`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use $bundleError only for branches the bundler provably eliminates; never as a shipped runtime fallback","When adding platform-conditional code to builtins, cover every branch or make conditions constant-foldable at bundle time"],"tags":["bundler","builtins","codegen","todo","dead-code-elimination"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}