diff --git a/packages/next-swc/crates/next-core/src/next_import_map.rs b/packages/next-swc/crates/next-core/src/next_import_map.rs index 7a0596a186f63..116c65691817f 100644 --- a/packages/next-swc/crates/next-core/src/next_import_map.rs +++ b/packages/next-swc/crates/next-core/src/next_import_map.rs @@ -214,6 +214,15 @@ pub async fn get_next_server_import_map( ServerContextType::AppSSR { .. } | ServerContextType::AppRSC { .. } | ServerContextType::AppRoute { .. } => { + import_map.insert_exact_alias( + "next/head", + request_to_import_mapping(project_path, "next/dist/client/components/noop-head"), + ); + import_map.insert_exact_alias( + "next/dynamic", + request_to_import_mapping(project_path, "next/dist/shared/lib/app-dynamic"), + ); + for name in next_config.server_component_externals().await?.iter() { import_map.insert_exact_alias(name, external); import_map.insert_wildcard_alias(format!("{name}/"), external); @@ -251,6 +260,23 @@ pub async fn get_next_edge_import_map( insert_next_server_special_aliases(&mut import_map, ty).await?; + match ty { + ServerContextType::Pages { .. } | ServerContextType::PagesData { .. } => {} + ServerContextType::AppSSR { .. } + | ServerContextType::AppRSC { .. } + | ServerContextType::AppRoute { .. } => { + import_map.insert_exact_alias( + "next/head", + request_to_import_mapping(project_path, "next/dist/client/components/noop-head"), + ); + import_map.insert_exact_alias( + "next/dynamic", + request_to_import_mapping(project_path, "next/dist/shared/lib/app-dynamic"), + ); + } + ServerContextType::Middleware => {} + } + Ok(import_map.cell()) }