oven-sh/bun · error · Error
Do not use CommonJS module.exports in ESM modules. Use `expo
Error message
Do not use CommonJS module.exports in ESM modules. Use `export default { ... }` instead. See src/js/README.md What it means
Error "Do not use CommonJS module.exports in ESM modules. Use `export default { ... }` instead. See src/js/README.md" thrown in oven-sh/bun.
Source
Thrown at src/codegen/bundle-modules.ts:89
n--;
await Bun.sleep(5);
}
}
throw err;
}
const bunRepoRoot = path.join(CMAKE_BUILD_ROOT, "..", "..");
// Preprocess builtins
const bundledEntryPoints: string[] = [];
for (let i = 0; i < nativeStartIndex; i++) {
try {
const file = path.join(BASE, moduleList[i]);
let input = fs.readFileSync(file, "utf8");
if (!/\bexport\s+(?:function|class|const|default|{)/.test(input)) {
if (input.includes("module.exports")) {
throw new Error(
"Do not use CommonJS module.exports in ESM modules. Use `export default { ... }` instead. See src/js/README.md",
);
} else {
throw new Error(
`Internal modules must have at least one ESM export statement in '${path.relative(bunRepoRoot, file)}' — see src/js/README.md`,
);
}
}
// TODO: there is no reason this cannot be converted automatically.
// import { ... } from '...' -> `const { ... } = require('...')`
const scannedImports = t.scan(input);
for (const imp of scannedImports.imports) {
if (imp.kind === "import-statement") {
var isBuiltin = true;
try {
if (!builtinModules.includes(imp.path)) {
requireTransformer(imp.path, moduleList[i]);View on GitHub (pinned to 8c5296ac45)
When it happens
Trigger: Thrown at src/codegen/bundle-modules.ts:89 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16).
Data as JSON: /api/errors/dea2b0b698e3276d.
Report an issue: GitHub.