Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

turbopack: Rewrite ESM modules to CJS during client transition #55693

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::{bail, Result};
use turbo_tasks::{Value, Vc};
use turbopack_binding::turbopack::{
core::{
file_source::FileSource,
module::Module,
reference_type::{EntryReferenceSubType, ReferenceType},
source::Source,
Expand Down Expand Up @@ -45,8 +46,19 @@ impl Transition for NextEcmascriptClientReferenceTransition {
context: Vc<ModuleAssetContext>,
_reference_type: Value<ReferenceType>,
) -> Result<Vc<Box<dyn Module>>> {
let ident = source.ident().await?;
let ident_path = ident.path.await?;
let client_source = if ident_path.path.contains("next/dist/esm/") {
let path = ident
.path
.root()
.join(ident_path.path.replace("next/dist/esm/", "next/dist/"));
Vc::upcast(FileSource::new_with_query(path, ident.query))
} else {
source
};
let client_module = self.client_transition.process(
source,
client_source,
context,
Value::new(ReferenceType::Entry(
EntryReferenceSubType::AppClientComponent,
Expand Down
Loading