{"record":{"id":"290b346130bb73a7","repo":"oven-sh/bun","slug":"internal-modules-must-have-at-least-one-esm-export","errorCode":null,"errorMessage":"Internal modules must have at least one ESM export statement in '${path.relative(bunRepoRoot, file)}' — see src/js/README.md","messagePattern":"Internal modules must have at least one ESM export statement in '(.+?)' — see src/js/README\\.md","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/bundle-modules.ts","lineNumber":93,"sourceCode":"  throw err;\n}\n\nconst bunRepoRoot = path.join(CMAKE_BUILD_ROOT, \"..\", \"..\");\n\n// Preprocess builtins\nconst bundledEntryPoints: string[] = [];\nfor (let i = 0; i < nativeStartIndex; i++) {\n  try {\n    const file = path.join(BASE, moduleList[i]);\n    let input = fs.readFileSync(file, \"utf8\");\n\n    if (!/\\bexport\\s+(?:function|class|const|default|{)/.test(input)) {\n      if (input.includes(\"module.exports\")) {\n        throw new Error(\n          \"Do not use CommonJS module.exports in ESM modules. Use `export default { ... }` instead. See src/js/README.md\",\n        );\n      } else {\n        throw new Error(\n          `Internal modules must have at least one ESM export statement in '${path.relative(bunRepoRoot, file)}' — see src/js/README.md`,\n        );\n      }\n    }\n\n    // TODO: there is no reason this cannot be converted automatically.\n    // import { ... } from '...' -> `const { ... } = require('...')`\n    const scannedImports = t.scan(input);\n    for (const imp of scannedImports.imports) {\n      if (imp.kind === \"import-statement\") {\n        var isBuiltin = true;\n        try {\n          if (!builtinModules.includes(imp.path)) {\n            requireTransformer(imp.path, moduleList[i]);\n          }\n        } catch {\n          isBuiltin = false;\n        }","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/bundle-modules.ts#L75-L111","documentation":"Error \"Internal modules must have at least one ESM export statement in '${path.relative(bunRepoRoot, file)}' — see src/js/README.md\" thrown in oven-sh/bun.","triggerScenarios":"Thrown at src/codegen/bundle-modules.ts:93 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}