Skip to content

Commit

Permalink
Turbopack: Emit an issue on unknown module types instead of falling b…
Browse files Browse the repository at this point in the history
…ack to raw (#7785)

This causes Turbopack to emit an error-level issue when a module doesn’t
have a type set on it. Previously, it fell back to assuming a raw type.


Closes PACK-2802
  • Loading branch information
wbinnssmith committed Mar 21, 2024
1 parent b79f9a0 commit 25fa656
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 19 additions & 1 deletion crates/turbopack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,25 @@ async fn process_default_internal(
}
}

let module_type = current_module_type.unwrap_or(ModuleType::Raw).cell();
let module_type = match current_module_type {
Some(module_type) => module_type,
None => {
ModuleIssue {
ident,
title: StyledString::Text("Unknown module type".to_string()).cell(),
description: StyledString::Text(
r"This module doesn't have an associated type. Use a known file extension, or register a loader for it.
Read more: https://nextjs.org/docs/app/api-reference/next-config-js/turbo#webpack-loaders".to_string(),
)
.cell(),
}
.cell()
.emit();

return Ok(ProcessResult::Ignore.cell());
}
}.cell();

Ok(apply_module_type(
current_source,
Expand Down
6 changes: 6 additions & 0 deletions crates/turbopack/src/module_options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ impl ModuleOptions {
]),
vec![ModuleRuleEffect::ModuleType(ModuleType::Static)],
),
ModuleRule::new(
ModuleRuleCondition::any(vec![ModuleRuleCondition::ResourcePathEndsWith(
".node".to_string(),
)]),
vec![ModuleRuleEffect::ModuleType(ModuleType::Raw)],
),
ModuleRule::new(
ModuleRuleCondition::any(vec![ModuleRuleCondition::ResourcePathEndsWith(
".wasm".to_string(),
Expand Down

0 comments on commit 25fa656

Please sign in to comment.