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

Error "This require call is not allowed because the imported file "{}" contains a top-level await" thrown in oven-sh/bun.

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)

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.