oven-sh/bun · error
This require call is not allowed because the imported file
Error message
This require call is not allowed because the imported file "{}" contains a top-level await What it means
A CommonJS `require()` targets a module the linker has proven to contain a top-level `await`. CJS semantics cannot await, so the import record is rejected as a build error with the location of the require call; the message names the offending file.
Solutions
- Convert the require call to a top-level or dynamic `import()` so the ESM path with TLA is honored
- Remove the top-level await from the required file, or wrap its body in an async IIFE
- Move the require into an async context is NOT sufficient — require itself cannot await
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/bundler/LinkerContext.rs:1999 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/8abae2f3718148d3.
Report an issue: GitHub.
Appendix: source
Thrown at src/bundler/LinkerContext.rs:1999
text: text.into(),
location: bun_ast::Location::init_or_null(
Some(&input_files[parent_source_index as usize]),
ast_import_records[parent_source_index as usize].as_slice()
[tla_checks[parent_source_index as usize]
.import_record_index
as usize]
.range,
),
..Default::default()
});
}
let source: &Source = &input_files[source_index as usize];
let imported_pretty_path = &source.path.pretty;
let mut text = Vec::new();
use std::io::Write;
if imported_pretty_path[..] == tla_pretty_path[..] {
write!(&mut text, "This require call is not allowed because the imported file \"{}\" contains a top-level await", bstr::BStr::new(imported_pretty_path)).expect("infallible: in-memory write");
} else {
write!(&mut text, "This require call is not allowed because the transitive dependency \"{}\" contains a top-level await", bstr::BStr::new(tla_pretty_path)).expect("infallible: in-memory write");
}
// Split-borrow with `source`/`record` (parse_graph backref
// slices) — `log_disjoint` returns the disjoint backref.
self.log_disjoint().add_range_error_with_notes(
Some(source),
record.range,
text,
notes.into_boxed_slice(),
);
}
}
}
}
}
View on GitHub (pinned to 8c5296ac45)