From c16bbffaece41798413eb151f2833e47bc6fd92a Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Tue, 9 Dec 2025 16:41:17 -0800 Subject: [PATCH] Turbopack: Improve the description on InvalidLoaderRuleConditionIssue --- crates/next-core/src/next_config.rs | 37 +++++++++++++++++++---------- examples/basic-css/next.config.js | 13 ++++++++++ 2 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 examples/basic-css/next.config.js diff --git a/crates/next-core/src/next_config.rs b/crates/next-core/src/next_config.rs index 912615887077..e7ca235b642b 100644 --- a/crates/next-core/src/next_config.rs +++ b/crates/next-core/src/next_config.rs @@ -1283,6 +1283,7 @@ impl Issue for InvalidLoaderRuleRenameAsIssue { #[turbo_tasks::value(shared)] struct InvalidLoaderRuleConditionIssue { + error_string: RcStr, condition: ConfigConditionItem, config_file_path: FileSystemPath, } @@ -1307,7 +1308,15 @@ impl Issue for InvalidLoaderRuleConditionIssue { #[turbo_tasks::function] async fn description(&self) -> Result> { Ok(Vc::cell(Some( - StyledString::Text(RcStr::from(format!("{:#?}", self.condition))).resolved_cell(), + StyledString::Stack(vec![ + StyledString::Line(vec![ + StyledString::Text(rcstr!("Encountered the following error: ")), + StyledString::Code(self.error_string.clone()), + ]), + StyledString::Text(rcstr!("While processing the condition:")), + StyledString::Code(RcStr::from(format!("{:#?}", self.condition))), + ]) + .resolved_cell(), ))) } @@ -1497,19 +1506,21 @@ impl NextConfig { // convert from Next.js-specific condition type to internal Turbopack // condition type let condition = if let Some(condition) = condition { - if let Ok(cond) = ConditionItem::try_from(condition.clone()) { - Some(cond) - } else { - InvalidLoaderRuleConditionIssue { - condition: condition.clone(), - config_file_path: self - .config_file_path(project_path.clone()) - .owned() - .await?, + match ConditionItem::try_from(condition.clone()) { + Ok(cond) => Some(cond), + Err(err) => { + InvalidLoaderRuleConditionIssue { + error_string: RcStr::from(err.to_string()), + condition: condition.clone(), + config_file_path: self + .config_file_path(project_path.clone()) + .owned() + .await?, + } + .resolved_cell() + .emit(); + None } - .resolved_cell() - .emit(); - None } } else { None diff --git a/examples/basic-css/next.config.js b/examples/basic-css/next.config.js new file mode 100644 index 000000000000..7143efc0dba0 --- /dev/null +++ b/examples/basic-css/next.config.js @@ -0,0 +1,13 @@ +module.exports = { + turbopack: { + rules: { + "*.svg": { + loaders: ["@svgr/webpack"], + as: "*.js", + condition: { + path: /abc/, + }, + }, + }, + }, +};