Skip to content

Commit

Permalink
fix esm require
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Apr 22, 2024
1 parent 25daefb commit a87dedb
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions crates/turbopack-ecmascript/src/references/external_module.rs
Expand Up @@ -64,18 +64,28 @@ impl CachedExternalModule {
pub fn content(&self) -> Result<Vc<EcmascriptModuleContent>> {
let mut code = RopeBuilder::default();

if self.external_type == CachedExternalType::EcmaScriptViaImport {
writeln!(
code,
"const mod = await __turbopack_external_import__({});",
StringifyJs(&self.request)
)?;
} else {
writeln!(
code,
"const mod = __turbopack_external_require__({});",
StringifyJs(&self.request)
)?;
match self.external_type {
CachedExternalType::CommonJs => {
writeln!(
code,
"const mod = __turbopack_external_require__({});",
StringifyJs(&self.request)
)?;
}
CachedExternalType::EcmaScriptViaRequire => {
writeln!(
code,
"const mod = __turbopack_external_require__({}, true);",
StringifyJs(&self.request)
)?;
}
CachedExternalType::EcmaScriptViaImport => {
writeln!(
code,
"const mod = await __turbopack_external_import__({});",
StringifyJs(&self.request)
)?;
}
}

writeln!(code)?;
Expand Down

0 comments on commit a87dedb

Please sign in to comment.