Unverified Commit 9b8a7a10 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: improve issue printing colors (#94858)

1. Align the code highlight marker color with the issue severity
2. Make the issue title colored
3. Prefix issues with `Warning` or `Error`


<img width="1383" height="862" alt="Bildschirmfoto 2026-06-16 um 18 59
03"
src="https://github.com/user-attachments/assets/f98c606d-4ea8-40c2-836d-e395f1df904c"
/>


<img width="1039" height="450" alt="Bildschirmfoto 2026-06-16 um 19 03
39"
src="https://github.com/user-attachments/assets/2747f914-0587-4178-a87d-344f24715c96"
/>



<details>
<summary>Old</summary>

<img width="1267" height="745" alt="Bildschirmfoto 2026-06-16 um 17 04
35"
src="https://github.com/user-attachments/assets/837739ff-82f7-4ea2-8767-ca7d866a8570"
/>

</details>
parent 71b70e01
use criterion::{Criterion, black_box, criterion_group, criterion_main}; use criterion::{Criterion, black_box, criterion_group, criterion_main};
use next_code_frame::{CodeFrameLocation, CodeFrameOptions, Language, Location, render_code_frame}; use next_code_frame::{
CodeFrameColorMode, CodeFrameLocation, CodeFrameOptions, Language, Location, render_code_frame,
};
/// Generate a realistic small TypeScript/React file (~300 lines). /// Generate a realistic small TypeScript/React file (~300 lines).
fn generate_small_file() -> String { fn generate_small_file() -> String {
...@@ -120,7 +122,7 @@ fn bench_small_file(c: &mut Criterion) { ...@@ -120,7 +122,7 @@ fn bench_small_file(c: &mut Criterion) {
let options = CodeFrameOptions { let options = CodeFrameOptions {
highlight_code: true, highlight_code: true,
color: true, color: CodeFrameColorMode::Error,
max_width: 100, max_width: 100,
language: Language::JavaScript, language: Language::JavaScript,
..Default::default() ..Default::default()
...@@ -149,7 +151,7 @@ fn bench_large_file(c: &mut Criterion) { ...@@ -149,7 +151,7 @@ fn bench_large_file(c: &mut Criterion) {
let options = CodeFrameOptions { let options = CodeFrameOptions {
highlight_code: true, highlight_code: true,
color: true, color: CodeFrameColorMode::Error,
max_width: 100, max_width: 100,
language: Language::JavaScript, language: Language::JavaScript,
..Default::default() ..Default::default()
...@@ -181,7 +183,7 @@ fn bench_minified_file(c: &mut Criterion) { ...@@ -181,7 +183,7 @@ fn bench_minified_file(c: &mut Criterion) {
let options = CodeFrameOptions { let options = CodeFrameOptions {
highlight_code: true, highlight_code: true,
color: true, color: CodeFrameColorMode::Error,
max_width: 100, max_width: 100,
language: Language::JavaScript, language: Language::JavaScript,
..Default::default() ..Default::default()
......
...@@ -4,7 +4,10 @@ use anyhow::{Result, bail}; ...@@ -4,7 +4,10 @@ use anyhow::{Result, bail};
use serde::Deserialize; use serde::Deserialize;
use unicode_width::UnicodeWidthChar; use unicode_width::UnicodeWidthChar;
use crate::highlight::{ColorScheme, Language, Lines, apply_line_highlights, extract_highlights}; use crate::highlight::{
ANSI_CODE_CYAN_BOLD, ANSI_CODE_RED_BOLD, ANSI_CODE_YELLOW_BOLD, ColorScheme, Language, Lines,
apply_line_highlights, extract_highlights,
};
/// Compute the display width of a string slice in terminal columns. /// Compute the display width of a string slice in terminal columns.
/// ///
...@@ -53,6 +56,15 @@ pub struct CodeFrameLocation { ...@@ -53,6 +56,15 @@ pub struct CodeFrameLocation {
pub end: Option<Location>, pub end: Option<Location>,
} }
/// The severity of the message (default: "error"), influences the color mode.
#[derive(Debug, Copy, Clone, Deserialize, PartialEq, Eq)]
pub enum CodeFrameColorMode {
None,
Error,
Warning,
Info,
}
/// Options for rendering the code frame /// Options for rendering the code frame
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase", default)] #[serde(rename_all = "camelCase", default)]
...@@ -62,7 +74,7 @@ pub struct CodeFrameOptions { ...@@ -62,7 +74,7 @@ pub struct CodeFrameOptions {
/// Number of lines to show after the error /// Number of lines to show after the error
pub lines_below: usize, pub lines_below: usize,
/// Whether to use ANSI color output /// Whether to use ANSI color output
pub color: bool, pub color: CodeFrameColorMode,
/// Whether to attempt syntax highlighting /// Whether to attempt syntax highlighting
pub highlight_code: bool, pub highlight_code: bool,
/// Optional message to display with the error /// Optional message to display with the error
...@@ -81,7 +93,7 @@ impl Default for CodeFrameOptions { ...@@ -81,7 +93,7 @@ impl Default for CodeFrameOptions {
Self { Self {
lines_above: 2, lines_above: 2,
lines_below: 3, lines_below: 3,
color: false, color: CodeFrameColorMode::None,
highlight_code: false, highlight_code: false,
message: None, message: None,
max_width: 100, max_width: 100,
...@@ -287,7 +299,7 @@ pub fn render_code_frame( ...@@ -287,7 +299,7 @@ pub fn render_code_frame(
available_code_width, available_code_width,
); );
let line_highlights = if options.color && options.highlight_code { let line_highlights = if options.color != CodeFrameColorMode::None && options.highlight_code {
Some(extract_highlights( Some(extract_highlights(
&lines, &lines,
first_line_idx..last_line_idx, first_line_idx..last_line_idx,
...@@ -298,11 +310,13 @@ pub fn render_code_frame( ...@@ -298,11 +310,13 @@ pub fn render_code_frame(
None None
}; };
let color_scheme = if options.color { let color_scheme = match options.color {
ColorScheme::colored() CodeFrameColorMode::None => ColorScheme::plain(),
} else { CodeFrameColorMode::Error => ColorScheme::colored(ANSI_CODE_RED_BOLD),
ColorScheme::plain() CodeFrameColorMode::Warning => ColorScheme::colored(ANSI_CODE_YELLOW_BOLD),
CodeFrameColorMode::Info => ColorScheme::colored(ANSI_CODE_CYAN_BOLD),
}; };
let mut output = String::new(); let mut output = String::new();
// Track whether we need a newline before the next section. // Track whether we need a newline before the next section.
// By prepending newlines instead of appending them we avoid a // By prepending newlines instead of appending them we avoid a
......
...@@ -107,6 +107,16 @@ static JS_KEYWORDS: phf::Set<&'static str> = phf_set! { ...@@ -107,6 +107,16 @@ static JS_KEYWORDS: phf::Set<&'static str> = phf_set! {
"yield", "yield",
}; };
pub(crate) const ANSI_CODE_RESET: &str = "\x1b[0m";
pub(crate) const ANSI_CODE_CYAN: &str = "\x1b[36m";
pub(crate) const ANSI_CODE_YELLOW: &str = "\x1b[33m";
pub(crate) const ANSI_CODE_GREEN: &str = "\x1b[32m";
pub(crate) const ANSI_CODE_MAGENTA: &str = "\x1b[35m";
pub(crate) const ANSI_CODE_GRAY: &str = "\x1b[90m";
pub(crate) const ANSI_CODE_RED_BOLD: &str = "\x1b[31m\x1b[1m";
pub(crate) const ANSI_CODE_YELLOW_BOLD: &str = "\x1b[33m\x1b[1m";
pub(crate) const ANSI_CODE_CYAN_BOLD: &str = "\x1b[36m\x1b[1m";
/// ANSI color codes for token types /// ANSI color codes for token types
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct ColorScheme { pub struct ColorScheme {
...@@ -124,18 +134,18 @@ pub struct ColorScheme { ...@@ -124,18 +134,18 @@ pub struct ColorScheme {
impl ColorScheme { impl ColorScheme {
/// Get a color scheme with ANSI colors (matching babel-code-frame) /// Get a color scheme with ANSI colors (matching babel-code-frame)
pub const fn colored() -> Self { pub const fn colored(marker_color: &'static str) -> Self {
Self { Self {
reset: "\x1b[0m", reset: ANSI_CODE_RESET,
keyword: "\x1b[36m", // cyan keyword: ANSI_CODE_CYAN,
identifier: "\x1b[33m", // yellow identifier: ANSI_CODE_YELLOW,
string: "\x1b[32m", // green string: ANSI_CODE_GREEN,
number: "\x1b[35m", // magenta number: ANSI_CODE_MAGENTA,
regex: "\x1b[35m", // magenta regex: ANSI_CODE_MAGENTA,
comment: "\x1b[90m", // gray comment: ANSI_CODE_GRAY,
gutter: "\x1b[90m", // gray gutter: ANSI_CODE_GRAY,
marker: "\x1b[31m\x1b[1m", // red + bold marker: marker_color,
message: "\x1b[31m\x1b[1m", // red + bold (same as marker for now) message: marker_color,
} }
} }
...@@ -1059,7 +1069,7 @@ pub mod tests { ...@@ -1059,7 +1069,7 @@ pub mod tests {
fn test_apply_line_highlights_basic() { fn test_apply_line_highlights_basic() {
let source = "const Foo = 123"; let source = "const Foo = 123";
let highlights = extract_highlights(&Lines::new(source), 0..usize::MAX, JS, None); let highlights = extract_highlights(&Lines::new(source), 0..usize::MAX, JS, None);
let color_scheme = ColorScheme::colored(); let color_scheme = ColorScheme::colored(ANSI_CODE_RED_BOLD);
let result = apply_line_highlights(source, &highlights[0], &color_scheme, 0, 0); let result = apply_line_highlights(source, &highlights[0], &color_scheme, 0, 0);
...@@ -1112,7 +1122,7 @@ pub mod tests { ...@@ -1112,7 +1122,7 @@ pub mod tests {
fn test_apply_line_highlights_with_truncation() { fn test_apply_line_highlights_with_truncation() {
let source = "const Foo = 123"; let source = "const Foo = 123";
let highlights = extract_highlights(&Lines::new(source), 0..usize::MAX, JS, None); let highlights = extract_highlights(&Lines::new(source), 0..usize::MAX, JS, None);
let color_scheme = ColorScheme::colored(); let color_scheme = ColorScheme::colored(ANSI_CODE_RED_BOLD);
// Truncate to show "Foo = 123" (offset 6, length 9, no prefix) // Truncate to show "Foo = 123" (offset 6, length 9, no prefix)
let visible = &source[6..]; let visible = &source[6..];
...@@ -1133,7 +1143,7 @@ pub mod tests { ...@@ -1133,7 +1143,7 @@ pub mod tests {
let source = r#"const x = "hello world";"#; let source = r#"const x = "hello world";"#;
let truncation_offset = 15; let truncation_offset = 15;
let highlights = extract_highlights(&Lines::new(source), 0..usize::MAX, JS, None); let highlights = extract_highlights(&Lines::new(source), 0..usize::MAX, JS, None);
let color_scheme = ColorScheme::colored(); let color_scheme = ColorScheme::colored(ANSI_CODE_RED_BOLD);
let visible = &source[truncation_offset..]; let visible = &source[truncation_offset..];
let result = let result =
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
mod frame; mod frame;
mod highlight; mod highlight;
pub use frame::{CodeFrameLocation, CodeFrameOptions, Location, render_code_frame}; pub use frame::{
CodeFrameColorMode, CodeFrameLocation, CodeFrameOptions, Location, render_code_frame,
};
pub use highlight::Language; pub use highlight::Language;
#[cfg(test)] #[cfg(test)]
......
use insta::assert_snapshot; use insta::assert_snapshot;
use crate::{ use crate::{
CodeFrameLocation, CodeFrameOptions, Location, highlight::tests::strip_ansi_codes, CodeFrameColorMode, CodeFrameLocation, CodeFrameOptions, Location,
render_code_frame, highlight::tests::strip_ansi_codes, render_code_frame,
}; };
/// Helper function to render code frame with highlighting enabled and ANSI codes stripped. /// Helper function to render code frame with highlighting enabled and ANSI codes stripped.
...@@ -31,7 +31,6 @@ fn test_simple_single_line_error() { ...@@ -31,7 +31,6 @@ fn test_simple_single_line_error() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
..Default::default() ..Default::default()
}; };
...@@ -56,7 +55,6 @@ fn test_empty_source() { ...@@ -56,7 +55,6 @@ fn test_empty_source() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
..Default::default() ..Default::default()
}; };
...@@ -76,7 +74,6 @@ fn test_invalid_line_number() { ...@@ -76,7 +74,6 @@ fn test_invalid_line_number() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
..Default::default() ..Default::default()
}; };
...@@ -137,7 +134,6 @@ fn test_multiline_error() { ...@@ -137,7 +134,6 @@ fn test_multiline_error() {
}), }),
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
..Default::default() ..Default::default()
}; };
...@@ -169,7 +165,6 @@ fn test_multiline_error_with_message() { ...@@ -169,7 +165,6 @@ fn test_multiline_error_with_message() {
}), }),
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
message: Some("Unexpected expression".to_string()), message: Some("Unexpected expression".to_string()),
..Default::default() ..Default::default()
...@@ -199,7 +194,6 @@ fn test_with_message() { ...@@ -199,7 +194,6 @@ fn test_with_message() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
message: Some("Expected semicolon".to_string()), message: Some("Expected semicolon".to_string()),
..Default::default() ..Default::default()
...@@ -229,7 +223,6 @@ fn test_long_line_single_error() { ...@@ -229,7 +223,6 @@ fn test_long_line_single_error() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
max_width: 100, max_width: 100,
..Default::default() ..Default::default()
...@@ -261,7 +254,6 @@ fn test_long_line_at_start() { ...@@ -261,7 +254,6 @@ fn test_long_line_at_start() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
max_width: 100, max_width: 100,
..Default::default() ..Default::default()
...@@ -291,7 +283,6 @@ fn test_long_line_at_end() { ...@@ -291,7 +283,6 @@ fn test_long_line_at_end() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
max_width: 100, max_width: 100,
..Default::default() ..Default::default()
...@@ -323,7 +314,6 @@ fn test_long_line_multiline_aligned() { ...@@ -323,7 +314,6 @@ fn test_long_line_multiline_aligned() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
max_width: 100, max_width: 100,
lines_above: 1, lines_above: 1,
...@@ -353,7 +343,6 @@ fn test_context_lines() { ...@@ -353,7 +343,6 @@ fn test_context_lines() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
lines_above: 2, lines_above: 2,
lines_below: 2, lines_below: 2,
...@@ -387,7 +376,6 @@ fn test_gutter_width_alignment() { ...@@ -387,7 +376,6 @@ fn test_gutter_width_alignment() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
lines_above: 2, lines_above: 2,
lines_below: 1, lines_below: 1,
...@@ -425,7 +413,6 @@ fn test_large_file() { ...@@ -425,7 +413,6 @@ fn test_large_file() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
lines_above: 2, lines_above: 2,
lines_below: 2, lines_below: 2,
...@@ -463,7 +450,6 @@ fn test_long_error_span() { ...@@ -463,7 +450,6 @@ fn test_long_error_span() {
}), // 300 char span }), // 300 char span
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
max_width: 100, max_width: 100,
..Default::default() ..Default::default()
...@@ -500,7 +486,6 @@ Another paragraph. ...@@ -500,7 +486,6 @@ Another paragraph.
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
..Default::default() ..Default::default()
}; };
...@@ -531,7 +516,6 @@ fn test_invalid_column_start_out_of_bounds() { ...@@ -531,7 +516,6 @@ fn test_invalid_column_start_out_of_bounds() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
..Default::default() ..Default::default()
}; };
...@@ -560,7 +544,6 @@ fn test_invalid_column_end_before_start() { ...@@ -560,7 +544,6 @@ fn test_invalid_column_end_before_start() {
}), // Before start - invalid }), // Before start - invalid
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
..Default::default() ..Default::default()
}; };
...@@ -589,7 +572,6 @@ fn test_invalid_column_both_out_of_bounds() { ...@@ -589,7 +572,6 @@ fn test_invalid_column_both_out_of_bounds() {
}), }),
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
..Default::default() ..Default::default()
}; };
...@@ -618,7 +600,6 @@ fn test_invalid_multiline_end_column_out_of_bounds() { ...@@ -618,7 +600,6 @@ fn test_invalid_multiline_end_column_out_of_bounds() {
}), // Way past end of "short" }), // Way past end of "short"
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
..Default::default() ..Default::default()
}; };
...@@ -653,7 +634,6 @@ fn test_column_semantics_explicit_end() { ...@@ -653,7 +634,6 @@ fn test_column_semantics_explicit_end() {
}), // Exclusive: marks [11, 12) = column 11 only }), // Exclusive: marks [11, 12) = column 11 only
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
..Default::default() ..Default::default()
}; };
...@@ -695,7 +675,6 @@ fn test_highlighting_doesnt_break_formatting() { ...@@ -695,7 +675,6 @@ fn test_highlighting_doesnt_break_formatting() {
// boundaries align correctly with char boundaries. // boundaries align correctly with char boundaries.
fn assert_highlighting_roundtrips(source: &str, location: &CodeFrameLocation) { fn assert_highlighting_roundtrips(source: &str, location: &CodeFrameLocation) {
let options_plain = CodeFrameOptions { let options_plain = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
..Default::default() ..Default::default()
}; };
...@@ -705,7 +684,6 @@ fn test_highlighting_doesnt_break_formatting() { ...@@ -705,7 +684,6 @@ fn test_highlighting_doesnt_break_formatting() {
// highlight_code=true with color=false should be identical to plain // highlight_code=true with color=false should be identical to plain
let options_highlighted = CodeFrameOptions { let options_highlighted = CodeFrameOptions {
color: false,
highlight_code: true, highlight_code: true,
..Default::default() ..Default::default()
}; };
...@@ -717,9 +695,9 @@ fn test_highlighting_doesnt_break_formatting() { ...@@ -717,9 +695,9 @@ fn test_highlighting_doesnt_break_formatting() {
"Highlighting with color=false should produce identical output" "Highlighting with color=false should produce identical output"
); );
// color=true with ANSI stripped should also match plain // color with ANSI stripped should also match plain
let options_colored = CodeFrameOptions { let options_colored = CodeFrameOptions {
color: true, color: CodeFrameColorMode::Error,
highlight_code: true, highlight_code: true,
..Default::default() ..Default::default()
}; };
...@@ -778,7 +756,6 @@ fn test_multibyte_cjk_no_truncation() { ...@@ -778,7 +756,6 @@ fn test_multibyte_cjk_no_truncation() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
..Default::default() ..Default::default()
}; };
...@@ -809,7 +786,6 @@ fn test_multibyte_cjk_with_truncation() { ...@@ -809,7 +786,6 @@ fn test_multibyte_cjk_with_truncation() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
max_width: 80, max_width: 80,
..Default::default() ..Default::default()
...@@ -840,7 +816,6 @@ fn test_multibyte_emoji() { ...@@ -840,7 +816,6 @@ fn test_multibyte_emoji() {
}), }),
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
..Default::default() ..Default::default()
}; };
...@@ -872,7 +847,6 @@ fn test_multibyte_mixed_with_truncation() { ...@@ -872,7 +847,6 @@ fn test_multibyte_mixed_with_truncation() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: false,
highlight_code: false, highlight_code: false,
max_width: 80, max_width: 80,
..Default::default() ..Default::default()
...@@ -902,7 +876,7 @@ fn test_multibyte_cjk_truncation_with_highlighting() { ...@@ -902,7 +876,7 @@ fn test_multibyte_cjk_truncation_with_highlighting() {
end: None, end: None,
}; };
let options = CodeFrameOptions { let options = CodeFrameOptions {
color: true, color: CodeFrameColorMode::Error,
highlight_code: true, highlight_code: true,
max_width: 80, max_width: 80,
..Default::default() ..Default::default()
......
use napi::bindgen_prelude::*; use napi::bindgen_prelude::*;
use napi_derive::napi; use napi_derive::napi;
use next_code_frame::{CodeFrameLocation, CodeFrameOptions, Language, Location, render_code_frame}; use next_code_frame::{
CodeFrameColorMode, CodeFrameLocation, CodeFrameOptions, Language, Location, render_code_frame,
};
/// Default max width when the caller doesn't provide one (e.g., no terminal). /// Default max width when the caller doesn't provide one (e.g., no terminal).
const DEFAULT_MAX_WIDTH: u32 = 100; const DEFAULT_MAX_WIDTH: u32 = 100;
...@@ -35,6 +37,14 @@ impl From<NapiCodeFrameLocation> for CodeFrameLocation { ...@@ -35,6 +37,14 @@ impl From<NapiCodeFrameLocation> for CodeFrameLocation {
} }
} }
#[napi]
#[derive(PartialEq, Eq)]
pub enum NapiCodeFrameColorMode {
Error,
Warning,
Info,
}
#[napi(object)] #[napi(object)]
#[derive(Default)] #[derive(Default)]
pub struct NapiCodeFrameOptions { pub struct NapiCodeFrameOptions {
...@@ -45,7 +55,7 @@ pub struct NapiCodeFrameOptions { ...@@ -45,7 +55,7 @@ pub struct NapiCodeFrameOptions {
/// Maximum width of the output in columns (default: 100) /// Maximum width of the output in columns (default: 100)
pub max_width: Option<u32>, pub max_width: Option<u32>,
/// Whether to use ANSI colors (default: false) /// Whether to use ANSI colors (default: false)
pub color: Option<bool>, pub color: Option<Either<NapiCodeFrameColorMode, bool>>,
/// Whether to highlight code syntax (default: follows color) /// Whether to highlight code syntax (default: follows color)
/// ///
/// This might be useful if syntax highlighting is very expensive or known to be useless for /// This might be useful if syntax highlighting is very expensive or known to be useless for
...@@ -67,12 +77,22 @@ fn parse_language(s: &Option<String>) -> Language { ...@@ -67,12 +77,22 @@ fn parse_language(s: &Option<String>) -> Language {
impl From<NapiCodeFrameOptions> for CodeFrameOptions { impl From<NapiCodeFrameOptions> for CodeFrameOptions {
fn from(opts: NapiCodeFrameOptions) -> Self { fn from(opts: NapiCodeFrameOptions) -> Self {
let color = match opts.color {
None | Some(Either::B(false)) => CodeFrameColorMode::None,
Some(Either::A(NapiCodeFrameColorMode::Error)) | Some(Either::B(true)) => {
CodeFrameColorMode::Error
}
Some(Either::A(NapiCodeFrameColorMode::Warning)) => CodeFrameColorMode::Warning,
Some(Either::A(NapiCodeFrameColorMode::Info)) => CodeFrameColorMode::Info,
};
CodeFrameOptions { CodeFrameOptions {
lines_above: opts.lines_above.unwrap_or(2) as usize, lines_above: opts.lines_above.unwrap_or(2) as usize,
lines_below: opts.lines_below.unwrap_or(3) as usize, lines_below: opts.lines_below.unwrap_or(3) as usize,
max_width: opts.max_width.unwrap_or(DEFAULT_MAX_WIDTH) as usize, max_width: opts.max_width.unwrap_or(DEFAULT_MAX_WIDTH) as usize,
color: opts.color.unwrap_or(false), color,
highlight_code: opts.highlight_code.unwrap_or(opts.color.unwrap_or(false)), highlight_code: opts
.highlight_code
.unwrap_or(color != CodeFrameColorMode::None),
message: opts.message, message: opts.message,
language: parse_language(&opts.language), language: parse_language(&opts.language),
} }
......
...@@ -12,7 +12,9 @@ use napi::{ ...@@ -12,7 +12,9 @@ use napi::{
threadsafe_function::{ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode}, threadsafe_function::{ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode},
}; };
use napi_derive::napi; use napi_derive::napi;
use next_code_frame::{CodeFrameLocation, CodeFrameOptions, Location, render_code_frame}; use next_code_frame::{
CodeFrameColorMode, CodeFrameLocation, CodeFrameOptions, Location, render_code_frame,
};
use regex::Regex; use regex::Regex;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use serde::Serialize; use serde::Serialize;
...@@ -149,7 +151,11 @@ fn is_internal(file_path: &str) -> bool { ...@@ -149,7 +151,11 @@ fn is_internal(file_path: &str) -> bool {
/// ///
/// Because this accesses the terminal size, this function call should not be cached (e.g. in /// Because this accesses the terminal size, this function call should not be cached (e.g. in
/// turbo-tasks). /// turbo-tasks).
fn render_source_code_frame(source: &PlainIssueSource, file_path: &str) -> Result<Option<String>> { fn render_source_code_frame(
severity: IssueSeverity,
source: &PlainIssueSource,
file_path: &str,
) -> Result<Option<String>> {
let Some((start, end)) = source.range else { let Some((start, end)) = source.range else {
return Ok(None); return Ok(None);
}; };
...@@ -184,7 +190,16 @@ fn render_source_code_frame(source: &PlainIssueSource, file_path: &str) -> Resul ...@@ -184,7 +190,16 @@ fn render_source_code_frame(source: &PlainIssueSource, file_path: &str) -> Resul
&content, &content,
&location, &location,
&CodeFrameOptions { &CodeFrameOptions {
color: true, color: match severity {
IssueSeverity::Bug | IssueSeverity::Fatal | IssueSeverity::Error => {
CodeFrameColorMode::Error
}
IssueSeverity::Warning => CodeFrameColorMode::Warning,
IssueSeverity::Hint
| IssueSeverity::Note
| IssueSeverity::Suggestion
| IssueSeverity::Info => CodeFrameColorMode::Info,
},
highlight_code: true, highlight_code: true,
max_width: terminal_size::terminal_size() max_width: terminal_size::terminal_size()
.map(|(w, _)| w.0 as usize) .map(|(w, _)| w.0 as usize)
...@@ -199,7 +214,7 @@ fn render_issue_code_frame(issue: &PlainIssue) -> Result<Option<String>> { ...@@ -199,7 +214,7 @@ fn render_issue_code_frame(issue: &PlainIssue) -> Result<Option<String>> {
let Some(source) = issue.source.as_ref() else { let Some(source) = issue.source.as_ref() else {
return Ok(None); return Ok(None);
}; };
render_source_code_frame(source, &issue.file_path) render_source_code_frame(issue.severity, source, &issue.file_path)
} }
#[napi(object)] #[napi(object)]
...@@ -248,8 +263,12 @@ impl From<&PlainIssue> for NapiIssue { ...@@ -248,8 +263,12 @@ impl From<&PlainIssue> for NapiIssue {
.iter() .iter()
.map(|s| NapiAdditionalIssueSource { .map(|s| NapiAdditionalIssueSource {
description: s.description.clone(), description: s.description.clone(),
code_frame: render_source_code_frame(&s.source, &s.source.asset.file_path) code_frame: render_source_code_frame(
.unwrap_or_default(), issue.severity,
&s.source,
&s.source.asset.file_path,
)
.unwrap_or_default(),
source: (&s.source).into(), source: (&s.source).into(),
}) })
.collect(), .collect(),
......
...@@ -1363,5 +1363,6 @@ ...@@ -1363,5 +1363,6 @@
"1362": "A <Link prefetch={true}> navigated to \"%s\", but Partial Prefetching is not enabled for that route, so its dynamic data was included in the prefetch. Enable Partial Prefetching app-wide by setting \\`partialPrefetching: true\\` in next.config, or per-route by exporting \\`const prefetch = 'partial'\\` from the page or layout.", "1362": "A <Link prefetch={true}> navigated to \"%s\", but Partial Prefetching is not enabled for that route, so its dynamic data was included in the prefetch. Enable Partial Prefetching app-wide by setting \\`partialPrefetching: true\\` in next.config, or per-route by exporting \\`const prefetch = 'partial'\\` from the page or layout.",
"1363": "\\`experimental.turbopackRustReactCompiler\\` is only supported with Turbopack. Please remove the option or run Next.js with Turbopack in %s.", "1363": "\\`experimental.turbopackRustReactCompiler\\` is only supported with Turbopack. Please remove the option or run Next.js with Turbopack in %s.",
"1364": "\\`experimental.turbopackRustReactCompiler\\` requires \\`reactCompiler\\` to be enabled. Please add \\`reactCompiler: true\\` in %s.", "1364": "\\`experimental.turbopackRustReactCompiler\\` requires \\`reactCompiler\\` to be enabled. Please add \\`reactCompiler: true\\` in %s.",
"1365": "Expected a dev tiered cache handler for kind \"%s\"." "1365": "Expected a dev tiered cache handler for kind \"%s\".",
"1366": "Turbopack build failed with %s %s:\\n%s"
} }
...@@ -64,7 +64,7 @@ export function printBuildErrors( ...@@ -64,7 +64,7 @@ export function printBuildErrors(
console.warn( console.warn(
`Turbopack build encountered ${ `Turbopack build encountered ${
topLevelWarnings.length topLevelWarnings.length
} warnings:\n${topLevelWarnings.join('\n')}` } ${topLevelWarnings.length === 1 ? 'warning' : 'warnings'}:\n${topLevelWarnings.join('\n')}`
) )
} }
...@@ -72,7 +72,7 @@ export function printBuildErrors( ...@@ -72,7 +72,7 @@ export function printBuildErrors(
console.error( console.error(
`Turbopack build encountered ${ `Turbopack build encountered ${
topLevelErrors.length topLevelErrors.length
} errors:\n${topLevelErrors.join('\n')}` } ${topLevelErrors.length === 1 ? 'error' : 'errors'}:\n${topLevelErrors.join('\n')}`
) )
} }
...@@ -80,7 +80,7 @@ export function printBuildErrors( ...@@ -80,7 +80,7 @@ export function printBuildErrors(
throw new Error( throw new Error(
`Turbopack build failed with ${ `Turbopack build failed with ${
topLevelFatalIssues.length topLevelFatalIssues.length
} errors:\n${topLevelFatalIssues.join('\n')}` } ${topLevelFatalIssues.length === 1 ? 'error' : 'errors'}:\n${topLevelFatalIssues.join('\n')}`
) )
} }
} }
...@@ -67,6 +67,11 @@ export interface NapiCodeFrameLocation { ...@@ -67,6 +67,11 @@ export interface NapiCodeFrameLocation {
start: NapiLocation start: NapiLocation
end?: NapiLocation end?: NapiLocation
} }
export const enum NapiCodeFrameColorMode {
Error = 0,
Warning = 1,
Info = 2,
}
export interface NapiCodeFrameOptions { export interface NapiCodeFrameOptions {
/** Number of lines to show above the error (default: 2) */ /** Number of lines to show above the error (default: 2) */
linesAbove?: number linesAbove?: number
...@@ -75,7 +80,7 @@ export interface NapiCodeFrameOptions { ...@@ -75,7 +80,7 @@ export interface NapiCodeFrameOptions {
/** Maximum width of the output in columns (default: 100) */ /** Maximum width of the output in columns (default: 100) */
maxWidth?: number maxWidth?: number
/** Whether to use ANSI colors (default: false) */ /** Whether to use ANSI colors (default: false) */
color?: boolean color?: NapiCodeFrameColorMode | boolean
/** /**
* Whether to highlight code syntax (default: follows color) * Whether to highlight code syntax (default: follows color)
* *
......
import stripAnsi from 'next/dist/compiled/strip-ansi'
import type { import type {
Issue, Issue,
PlainTraceItem, PlainTraceItem,
...@@ -36,10 +37,10 @@ describe('formatIssue', () => { ...@@ -36,10 +37,10 @@ describe('formatIssue', () => {
...baseIssue, ...baseIssue,
importTraces: [trace], importTraces: [trace],
} }
const output = formatIssue(issue) const output = stripAnsi(formatIssue(issue))
expect(output).toBe(`\ expect(output).toBe(`\
./src/app/page.ts ./src/app/page.ts
Module not found Error: Module not found
Import trace: Import trace:
client: client:
./src/app/page.ts ./src/app/page.ts
...@@ -63,10 +64,10 @@ https://nextjs.org/docs/messages/module-not-found ...@@ -63,10 +64,10 @@ https://nextjs.org/docs/messages/module-not-found
...baseIssue, ...baseIssue,
importTraces: [trace1, trace2], importTraces: [trace1, trace2],
} }
const output = formatIssue(issue) const output = stripAnsi(formatIssue(issue))
expect(output).toBe(`\ expect(output).toBe(`\
./src/app/page.ts ./src/app/page.ts
Module not found Error: Module not found
Import traces: Import traces:
client: client:
./src/app/page.ts ./src/app/page.ts
...@@ -94,10 +95,10 @@ https://nextjs.org/docs/messages/module-not-found ...@@ -94,10 +95,10 @@ https://nextjs.org/docs/messages/module-not-found
...baseIssue, ...baseIssue,
importTraces: [trace1, trace2], importTraces: [trace1, trace2],
} }
const output = formatIssue(issue) const output = stripAnsi(formatIssue(issue))
expect(output).toBe(`\ expect(output).toBe(`\
./src/app/page.ts ./src/app/page.ts
Module not found Error: Module not found
Import traces: Import traces:
#1 [client]: #1 [client]:
./src/app/page.ts ./src/app/page.ts
...@@ -133,10 +134,10 @@ https://nextjs.org/docs/messages/module-not-found ...@@ -133,10 +134,10 @@ https://nextjs.org/docs/messages/module-not-found
...baseIssue, ...baseIssue,
importTraces: [trace], importTraces: [trace],
} }
const output = formatIssue(issue) const output = stripAnsi(formatIssue(issue))
expect(output).toBe(`\ expect(output).toBe(`\
./src/app/page.ts ./src/app/page.ts
Module not found Error: Module not found
Import trace: Import trace:
./src/app/page.ts ./src/app/page.ts
./src/lib/foo.ts ./src/lib/foo.ts
......
...@@ -5,7 +5,7 @@ import type { ...@@ -5,7 +5,7 @@ import type {
TurbopackResult, TurbopackResult,
} from '../../../build/swc/types' } from '../../../build/swc/types'
import { bold, green, magenta, red } from '../../../lib/picocolors' import { bold, green, magenta, red, yellow } from '../../../lib/picocolors'
import { deobfuscateText } from '../magic-identifier' import { deobfuscateText } from '../magic-identifier'
import type { EntryKey } from './entry-key' import type { EntryKey } from './entry-key'
import * as Log from '../../../build/output/log' import * as Log from '../../../build/output/log'
...@@ -99,13 +99,29 @@ function formatFilePath(filePath: string): string { ...@@ -99,13 +99,29 @@ function formatFilePath(filePath: string): string {
} }
export function formatIssue(issue: Issue) { export function formatIssue(issue: Issue) {
const { filePath, title, description, detail, source, importTraces } = issue const {
filePath,
title,
description,
detail,
source,
importTraces,
severity,
} = issue
let { documentationLink } = issue let { documentationLink } = issue
const formattedTitle = renderStyledStringToErrorAnsi(title).replace( let formattedTitle = renderStyledStringToErrorAnsi(title).replace(
/\n/g, /\n/g,
'\n ' '\n '
) )
if (severity === 'bug' || severity === 'error' || severity === 'fatal') {
formattedTitle = bold(`${red('Error')}: ${formattedTitle}`)
} else if (severity === 'warning') {
formattedTitle = bold(`${yellow('Warning')}: ${formattedTitle}`)
} else {
formattedTitle = bold(`Info: ${formattedTitle}`)
}
// TODO: Use error codes to identify these // TODO: Use error codes to identify these
// TODO: Generalize adapting Turbopack errors to Next.js errors // TODO: Generalize adapting Turbopack errors to Next.js errors
if (formattedTitle.includes('Module not found')) { if (formattedTitle.includes('Module not found')) {
......
...@@ -52,7 +52,7 @@ describe('ReactRefreshLogBox-builtins app', () => { ...@@ -52,7 +52,7 @@ describe('ReactRefreshLogBox-builtins app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./node_modules/my-package/index.js (1:13) "source": "./node_modules/my-package/index.js (1:13)
Module not found: Can't resolve 'dns' Error: Module not found: Can't resolve 'dns'
> 1 | const dns = require('dns') > 1 | const dns = require('dns')
| ^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^",
"stack": [], "stack": [],
...@@ -119,7 +119,7 @@ describe('ReactRefreshLogBox-builtins app', () => { ...@@ -119,7 +119,7 @@ describe('ReactRefreshLogBox-builtins app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (1:1) "source": "./index.js (1:1)
Module not found: Can't resolve 'b' Error: Module not found: Can't resolve 'b'
> 1 | import Comp from 'b' > 1 | import Comp from 'b'
| ^^^^^^^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^^^^^^^",
"stack": [], "stack": [],
...@@ -188,7 +188,7 @@ describe('ReactRefreshLogBox-builtins app', () => { ...@@ -188,7 +188,7 @@ describe('ReactRefreshLogBox-builtins app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/page.js (2:1) "source": "./app/page.js (2:1)
Module not found: Can't resolve 'b' Error: Module not found: Can't resolve 'b'
> 2 | import Comp from 'b' > 2 | import Comp from 'b'
| ^^^^^^^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^^^^^^^",
"stack": [], "stack": [],
...@@ -254,7 +254,7 @@ describe('ReactRefreshLogBox-builtins app', () => { ...@@ -254,7 +254,7 @@ describe('ReactRefreshLogBox-builtins app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/page.js (2:1) "source": "./app/page.js (2:1)
Module not found: Can't resolve './non-existent.css' Error: Module not found: Can't resolve './non-existent.css'
> 2 | import './non-existent.css' > 2 | import './non-existent.css'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^",
"stack": [], "stack": [],
......
...@@ -285,7 +285,7 @@ describe('ReactRefreshLogBox app', () => { ...@@ -285,7 +285,7 @@ describe('ReactRefreshLogBox app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (7:1) "source": "./index.js (7:1)
Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`? Error: Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?
> 7 | } > 7 | }
| ^", | ^",
"stack": [], "stack": [],
...@@ -485,7 +485,7 @@ describe('ReactRefreshLogBox app', () => { ...@@ -485,7 +485,7 @@ describe('ReactRefreshLogBox app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.module.css (1:8) "source": "./index.module.css (1:8)
Parsing CSS source code failed Error: Parsing CSS source code failed
> 1 | .button > 1 | .button
| ^", | ^",
"stack": [], "stack": [],
...@@ -538,7 +538,7 @@ describe('ReactRefreshLogBox app', () => { ...@@ -538,7 +538,7 @@ describe('ReactRefreshLogBox app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.module.css "source": "./index.module.css
Transforming CSS failed Error: Transforming CSS failed
Selector "button" is not pure. Pure selectors must contain at least one local class or id. Selector "button" is not pure. Pure selectors must contain at least one local class or id.
Import traces: Import traces:
Client Component Browser: Client Component Browser:
...@@ -1436,7 +1436,7 @@ describe('ReactRefreshLogBox app', () => { ...@@ -1436,7 +1436,7 @@ describe('ReactRefreshLogBox app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/module.js (1:1) "source": "./app/module.js (1:1)
Module not found: Can't resolve 'non-existing-module' Error: Module not found: Can't resolve 'non-existing-module'
> 1 | import "non-existing-module" > 1 | import "non-existing-module"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
"stack": [], "stack": [],
...@@ -1509,7 +1509,7 @@ describe('ReactRefreshLogBox app', () => { ...@@ -1509,7 +1509,7 @@ describe('ReactRefreshLogBox app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/styles2.css (1:1) "source": "./app/styles2.css (1:1)
Module not found: Can't resolve './boom.css' Error: Module not found: Can't resolve './boom.css'
> 1 | @import "./boom.css" > 1 | @import "./boom.css"
| ^", | ^",
"stack": [], "stack": [],
......
...@@ -38,7 +38,7 @@ describe('ReactRefreshLogBox app', () => { ...@@ -38,7 +38,7 @@ describe('ReactRefreshLogBox app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/page.js (3:23) "source": "./app/page.js (3:23)
"getStaticProps" is not supported in app/. Read more: https://nextjs.org/docs/app/building-your-application/data-fetching Error: "getStaticProps" is not supported in app/. Read more: https://nextjs.org/docs/app/building-your-application/data-fetching
> 3 | export async function getStaticProps() { > 3 | export async function getStaticProps() {
| ^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^",
"stack": [], "stack": [],
......
...@@ -47,7 +47,7 @@ describe('Error recovery app', () => { ...@@ -47,7 +47,7 @@ describe('Error recovery app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (1:27) "source": "./index.js (1:27)
Expected '>', got '<eof>' Error: Expected '>', got '<eof>'
> 1 | export default () => <div/ > 1 | export default () => <div/
| ^", | ^",
"stack": [], "stack": [],
...@@ -140,7 +140,7 @@ describe('Error recovery app', () => { ...@@ -140,7 +140,7 @@ describe('Error recovery app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/server/page.js (2:28) "source": "./app/server/page.js (2:28)
Expected '}', got '<eof>' Error: Expected '}', got '<eof>'
> 2 | return <p>Hello world</p> > 2 | return <p>Hello world</p>
| ^", | ^",
"stack": [], "stack": [],
...@@ -224,7 +224,7 @@ describe('Error recovery app', () => { ...@@ -224,7 +224,7 @@ describe('Error recovery app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/client/page.js (2:28) "source": "./app/client/page.js (2:28)
Expected '}', got '<eof>' Error: Expected '}', got '<eof>'
> 2 | return <p>Hello world</p> > 2 | return <p>Hello world</p>
| ^", | ^",
"stack": [], "stack": [],
...@@ -659,7 +659,7 @@ describe('Error recovery app', () => { ...@@ -659,7 +659,7 @@ describe('Error recovery app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (10:42) "source": "./index.js (10:42)
Expected '}', got '<eof>' Error: Expected '}', got '<eof>'
> 10 | export default function FunctionNamed() { > 10 | export default function FunctionNamed() {
| ^", | ^",
"stack": [], "stack": [],
...@@ -719,7 +719,7 @@ describe('Error recovery app', () => { ...@@ -719,7 +719,7 @@ describe('Error recovery app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (10:42) "source": "./index.js (10:42)
Expected '}', got '<eof>' Error: Expected '}', got '<eof>'
> 10 | export default function FunctionNamed() { > 10 | export default function FunctionNamed() {
| ^", | ^",
"stack": [], "stack": [],
...@@ -911,7 +911,7 @@ describe('Error recovery app', () => { ...@@ -911,7 +911,7 @@ describe('Error recovery app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (5:5) "source": "./index.js (5:5)
Expected '{', got 'return' Error: Expected '{', got 'return'
> 5 | return <h1>Default Export</h1>; > 5 | return <h1>Default Export</h1>;
| ^^^^^^", | ^^^^^^",
"stack": [], "stack": [],
...@@ -994,7 +994,7 @@ describe('Error recovery app', () => { ...@@ -994,7 +994,7 @@ describe('Error recovery app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (5:5) "source": "./index.js (5:5)
Expected '{', got 'throw' Error: Expected '{', got 'throw'
> 5 | throw new Error('nooo'); > 5 | throw new Error('nooo');
| ^^^^^", | ^^^^^",
"stack": [], "stack": [],
...@@ -1120,7 +1120,7 @@ describe('Error recovery app', () => { ...@@ -1120,7 +1120,7 @@ describe('Error recovery app', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/page.js (1:4) "source": "./app/page.js (1:4)
Expected '}', got '<eof>' Error: Expected '}', got '<eof>'
> 1 | {{{ > 1 | {{{
| ^", | ^",
"stack": [], "stack": [],
......
...@@ -67,7 +67,7 @@ describe('Error Overlay invalid imports', () => { ...@@ -67,7 +67,7 @@ describe('Error Overlay invalid imports', () => {
if (process.env.IS_TURBOPACK_TEST) { if (process.env.IS_TURBOPACK_TEST) {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(` expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./app/comp2.js "./app/comp2.js
'styled-jsx' cannot be imported from a Server Component module Error: 'styled-jsx' cannot be imported from a Server Component module
It only works in a Client Component but none of its parents are marked with 'use client', so they're Server Components by default. It only works in a Client Component but none of its parents are marked with 'use client', so they're Server Components by default.
Import trace: Import trace:
...@@ -136,7 +136,7 @@ describe('Error Overlay invalid imports', () => { ...@@ -136,7 +136,7 @@ describe('Error Overlay invalid imports', () => {
if (process.env.IS_TURBOPACK_TEST) { if (process.env.IS_TURBOPACK_TEST) {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(` expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./app/foo.js (1:1) "./app/foo.js (1:1)
'client-only' cannot be imported from a Server Component module Error: 'client-only' cannot be imported from a Server Component module
> 1 | require("client-only") > 1 | require("client-only")
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
...@@ -235,7 +235,7 @@ describe('Error Overlay invalid imports', () => { ...@@ -235,7 +235,7 @@ describe('Error Overlay invalid imports', () => {
if (process.env.IS_TURBOPACK_TEST) { if (process.env.IS_TURBOPACK_TEST) {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(` expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./node_modules/client-only-package/index.js (1:1) "./node_modules/client-only-package/index.js (1:1)
'client-only' cannot be imported from a Server Component module Error: 'client-only' cannot be imported from a Server Component module
> 1 | require("client-only") > 1 | require("client-only")
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
...@@ -336,7 +336,7 @@ describe('Error Overlay invalid imports', () => { ...@@ -336,7 +336,7 @@ describe('Error Overlay invalid imports', () => {
if (process.env.IS_TURBOPACK_TEST) { if (process.env.IS_TURBOPACK_TEST) {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(` expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./node_modules/server-only-package/index.js (1:1) "./node_modules/server-only-package/index.js (1:1)
'server-only' cannot be imported from a Client Component module Error: 'server-only' cannot be imported from a Client Component module
> 1 | require("server-only") > 1 | require("server-only")
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
......
...@@ -176,7 +176,7 @@ describe('Error overlay - RSC build errors', () => { ...@@ -176,7 +176,7 @@ describe('Error overlay - RSC build errors', () => {
// turbopack emits the resolve issue first instead of the transform issue. // turbopack emits the resolve issue first instead of the transform issue.
expect(await session.getRedboxSource()).toMatchInlineSnapshot(` expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./app/server-with-errors/client-only-in-server/client-only-lib.js (1:1) "./app/server-with-errors/client-only-in-server/client-only-lib.js (1:1)
You're importing a component that imports client-only. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default. Error: You're importing a component that imports client-only. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.
Learn more: https://nextjs.org/docs/app/building-your-application/rendering Learn more: https://nextjs.org/docs/app/building-your-application/rendering
> 1 | import 'client-only' > 1 | import 'client-only'
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
...@@ -462,7 +462,7 @@ describe('Error overlay - RSC build errors', () => { ...@@ -462,7 +462,7 @@ describe('Error overlay - RSC build errors', () => {
expect(next.normalizeTestDirContent(await session.getRedboxSource())) expect(next.normalizeTestDirContent(await session.getRedboxSource()))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"./app/server-with-errors/error-file/error.js (1:1) "./app/server-with-errors/error-file/error.js (1:1)
app/server-with-errors/error-file/error.js must be a Client Component. Add the "use client" directive the top of the file to resolve this issue. Error: app/server-with-errors/error-file/error.js must be a Client Component. Add the "use client" directive the top of the file to resolve this issue.
Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client
> 1 | export default function Error() {} > 1 | export default function Error() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......
...@@ -112,7 +112,7 @@ describe('ReactRefreshLogBox _app _document', () => { ...@@ -112,7 +112,7 @@ describe('ReactRefreshLogBox _app _document', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./pages/_app.js (2:10) "source": "./pages/_app.js (2:10)
Expression expected Error: Expression expected
> 2 | return <<Component {...pageProps} />; > 2 | return <<Component {...pageProps} />;
| ^^", | ^^",
"stack": [], "stack": [],
...@@ -231,7 +231,7 @@ describe('ReactRefreshLogBox _app _document', () => { ...@@ -231,7 +231,7 @@ describe('ReactRefreshLogBox _app _document', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./pages/_document.js (3:36) "source": "./pages/_document.js (3:36)
Unexpected token \`{\`. Expected identifier, string literal, numeric literal or [ for the computed key Error: Unexpected token \`{\`. Expected identifier, string literal, numeric literal or [ for the computed key
> 3 | class MyDocument extends Document {{ > 3 | class MyDocument extends Document {{
| ^", | ^",
"stack": [], "stack": [],
......
...@@ -51,7 +51,7 @@ describe('ReactRefreshLogBox', () => { ...@@ -51,7 +51,7 @@ describe('ReactRefreshLogBox', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./node_modules/my-package/index.js (1:13) "source": "./node_modules/my-package/index.js (1:13)
Module not found: Can't resolve 'dns' Error: Module not found: Can't resolve 'dns'
> 1 | const dns = require('dns') > 1 | const dns = require('dns')
| ^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^",
"stack": [], "stack": [],
...@@ -118,7 +118,7 @@ describe('ReactRefreshLogBox', () => { ...@@ -118,7 +118,7 @@ describe('ReactRefreshLogBox', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (1:1) "source": "./index.js (1:1)
Module not found: Can't resolve 'b' Error: Module not found: Can't resolve 'b'
> 1 | import Comp from 'b' > 1 | import Comp from 'b'
| ^^^^^^^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^^^^^^^",
"stack": [], "stack": [],
...@@ -187,7 +187,7 @@ describe('ReactRefreshLogBox', () => { ...@@ -187,7 +187,7 @@ describe('ReactRefreshLogBox', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./pages/index.js (1:1) "source": "./pages/index.js (1:1)
Module not found: Can't resolve 'b' Error: Module not found: Can't resolve 'b'
> 1 | import Comp from 'b' > 1 | import Comp from 'b'
| ^^^^^^^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^^^^^^^",
"stack": [], "stack": [],
...@@ -262,7 +262,7 @@ describe('ReactRefreshLogBox', () => { ...@@ -262,7 +262,7 @@ describe('ReactRefreshLogBox', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./pages/_app.js (1:1) "source": "./pages/_app.js (1:1)
Module not found: Can't resolve './non-existent.css' Error: Module not found: Can't resolve './non-existent.css'
> 1 | import './non-existent.css' > 1 | import './non-existent.css'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^",
"stack": [], "stack": [],
......
...@@ -449,7 +449,7 @@ describe('ReactRefreshLogBox', () => { ...@@ -449,7 +449,7 @@ describe('ReactRefreshLogBox', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (7:1) "source": "./index.js (7:1)
Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`? Error: Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?
> 7 | } > 7 | }
| ^", | ^",
"stack": [], "stack": [],
...@@ -716,7 +716,7 @@ describe('ReactRefreshLogBox', () => { ...@@ -716,7 +716,7 @@ describe('ReactRefreshLogBox', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.module.css (1:8) "source": "./index.module.css (1:8)
Parsing CSS source code failed Error: Parsing CSS source code failed
> 1 | .button > 1 | .button
| ^", | ^",
"stack": [], "stack": [],
...@@ -769,7 +769,7 @@ describe('ReactRefreshLogBox', () => { ...@@ -769,7 +769,7 @@ describe('ReactRefreshLogBox', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.module.css "source": "./index.module.css
Transforming CSS failed Error: Transforming CSS failed
Selector "button" is not pure. Pure selectors must contain at least one local class or id. Selector "button" is not pure. Pure selectors must contain at least one local class or id.
Import traces: Import traces:
Browser: Browser:
......
...@@ -47,7 +47,7 @@ describe('pages/ error recovery', () => { ...@@ -47,7 +47,7 @@ describe('pages/ error recovery', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (1:27) "source": "./index.js (1:27)
Expected '>', got '<eof>' Error: Expected '>', got '<eof>'
> 1 | export default () => <div/ > 1 | export default () => <div/
| ^", | ^",
"stack": [], "stack": [],
...@@ -405,7 +405,7 @@ describe('pages/ error recovery', () => { ...@@ -405,7 +405,7 @@ describe('pages/ error recovery', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (5:5) "source": "./index.js (5:5)
Expected '{', got 'return' Error: Expected '{', got 'return'
> 5 | return <h1>Default Export</h1>; > 5 | return <h1>Default Export</h1>;
| ^^^^^^", | ^^^^^^",
"stack": [], "stack": [],
...@@ -489,7 +489,7 @@ describe('pages/ error recovery', () => { ...@@ -489,7 +489,7 @@ describe('pages/ error recovery', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (5:5) "source": "./index.js (5:5)
Expected '{', got 'throw' Error: Expected '{', got 'throw'
> 5 | throw new Error('nooo'); > 5 | throw new Error('nooo');
| ^^^^^", | ^^^^^",
"stack": [], "stack": [],
...@@ -823,7 +823,7 @@ describe('pages/ error recovery', () => { ...@@ -823,7 +823,7 @@ describe('pages/ error recovery', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (7:42) "source": "./index.js (7:42)
Expected '}', got '<eof>' Error: Expected '}', got '<eof>'
> 7 | export default function FunctionNamed() { > 7 | export default function FunctionNamed() {
| ^", | ^",
"stack": [], "stack": [],
...@@ -888,7 +888,7 @@ describe('pages/ error recovery', () => { ...@@ -888,7 +888,7 @@ describe('pages/ error recovery', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (7:42) "source": "./index.js (7:42)
Expected '}', got '<eof>' Error: Expected '}', got '<eof>'
> 7 | export default function FunctionNamed() { > 7 | export default function FunctionNamed() {
| ^", | ^",
"stack": [], "stack": [],
......
...@@ -55,7 +55,7 @@ describe('Error Overlay for server components compiler errors in pages', () => { ...@@ -55,7 +55,7 @@ describe('Error Overlay for server components compiler errors in pages', () => {
expect(next.normalizeTestDirContent(await session.getRedboxSource())) expect(next.normalizeTestDirContent(await session.getRedboxSource()))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"./components/Comp.js (1:1) "./components/Comp.js (1:1)
You're importing a module that depends on "next/headers". This API is only available in Server Components in the App Router, but you are using it in the Pages Router. Error: You're importing a module that depends on "next/headers". This API is only available in Server Components in the App Router, but you are using it in the Pages Router.
Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
> 1 | import { cookies } from 'next/headers' > 1 | import { cookies } from 'next/headers'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -141,7 +141,7 @@ describe('Error Overlay for server components compiler errors in pages', () => { ...@@ -141,7 +141,7 @@ describe('Error Overlay for server components compiler errors in pages', () => {
expect(next.normalizeTestDirContent(await session.getRedboxSource())) expect(next.normalizeTestDirContent(await session.getRedboxSource()))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"./components/Comp.js (1:1) "./components/Comp.js (1:1)
You're importing a module that depends on "server-only". This API is only available in Server Components in the App Router, but you are using it in the Pages Router. Error: You're importing a module that depends on "server-only". This API is only available in Server Components in the App Router, but you are using it in the Pages Router.
Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
> 1 | import 'server-only' > 1 | import 'server-only'
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
...@@ -229,7 +229,7 @@ describe('Error Overlay for server components compiler errors in pages', () => { ...@@ -229,7 +229,7 @@ describe('Error Overlay for server components compiler errors in pages', () => {
expect(next.normalizeTestDirContent(await session.getRedboxSource())) expect(next.normalizeTestDirContent(await session.getRedboxSource()))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"./components/Comp.js (1:10) "./components/Comp.js (1:10)
You're importing a module that depends on "after". This API is only available in Server Components in the App Router, but you are using it in the Pages Router. Error: You're importing a module that depends on "after". This API is only available in Server Components in the App Router, but you are using it in the Pages Router.
Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
> 1 | import { after } from 'next/server' > 1 | import { after } from 'next/server'
| ^^^^^ | ^^^^^
...@@ -319,7 +319,7 @@ describe('Error Overlay for server components compiler errors in pages', () => { ...@@ -319,7 +319,7 @@ describe('Error Overlay for server components compiler errors in pages', () => {
expect(next.normalizeTestDirContent(await session.getRedboxSource())) expect(next.normalizeTestDirContent(await session.getRedboxSource()))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"./components/Comp.js (1:1) "./components/Comp.js (1:1)
You're importing a module that depends on "next/root-params". This API is only available in Server Components in the App Router, but you are using it in the Pages Router. Error: You're importing a module that depends on "next/root-params". This API is only available in Server Components in the App Router, but you are using it in the Pages Router.
Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components Learn more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
> 1 | import { foo } from 'next/root-params' > 1 | import { foo } from 'next/root-params'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......
...@@ -133,7 +133,7 @@ describe('Cache Components Dev Errors', () => { ...@@ -133,7 +133,7 @@ describe('Cache Components Dev Errors', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/page.tsx (1:14) "source": "./app/page.tsx (1:14)
Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it. Error: Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it.
> 1 | export const revalidate = 10 > 1 | export const revalidate = 10
| ^^^^^^^^^^", | ^^^^^^^^^^",
"stack": [], "stack": [],
......
...@@ -24,7 +24,7 @@ describe('app-dir - server-component-next-dynamic-ssr-false', () => { ...@@ -24,7 +24,7 @@ describe('app-dir - server-component-next-dynamic-ssr-false', () => {
) )
expect(redbox.source).toMatchInlineSnapshot(` expect(redbox.source).toMatchInlineSnapshot(`
"./app/page.js (3:23) "./app/page.js (3:23)
\`ssr: false\` is not allowed with \`next/dynamic\` in Server Components. Please move it into a Client Component. Error: \`ssr: false\` is not allowed with \`next/dynamic\` in Server Components. Please move it into a Client Component.
1 | import dynamic from 'next/dynamic' 1 | import dynamic from 'next/dynamic'
2 | 2 |
> 3 | const DynamicClient = dynamic(() => import('./client'), { ssr: false }) > 3 | const DynamicClient = dynamic(() => import('./client'), { ssr: false })
......
...@@ -185,7 +185,7 @@ describe('react-dom/server in React Server environment', () => { ...@@ -185,7 +185,7 @@ describe('react-dom/server in React Server environment', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/exports/app-code/react-dom-server-edge-implicit/page.js (3:1) "source": "./app/exports/app-code/react-dom-server-edge-implicit/page.js (3:1)
You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security. Error: You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.
Learn more: https://nextjs.org/docs/app/building-your-application/rendering Learn more: https://nextjs.org/docs/app/building-your-application/rendering
> 3 | import ReactDOMServerEdgeDefault from 'react-dom/server' > 3 | import ReactDOMServerEdgeDefault from 'react-dom/server'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
...@@ -327,7 +327,7 @@ describe('react-dom/server in React Server environment', () => { ...@@ -327,7 +327,7 @@ describe('react-dom/server in React Server environment', () => {
{ {
"description": "You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.", "description": "You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.",
"source": "./app/exports/app-code/react-dom-server-node-implicit/page.js (3:1) "source": "./app/exports/app-code/react-dom-server-node-implicit/page.js (3:1)
You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security. Error: You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.
Learn more: https://nextjs.org/docs/app/building-your-application/rendering Learn more: https://nextjs.org/docs/app/building-your-application/rendering
1 | import * as ReactDOMServerNode from 'react-dom/server' 1 | import * as ReactDOMServerNode from 'react-dom/server'
2 | // Fine to drop once React is on ESM 2 | // Fine to drop once React is on ESM
......
...@@ -164,7 +164,7 @@ export function runErrorRecoveryHmrTest(nextConfig: { ...@@ -164,7 +164,7 @@ export function runErrorRecoveryHmrTest(nextConfig: {
if (process.env.IS_TURBOPACK_TEST) { if (process.env.IS_TURBOPACK_TEST) {
expect(source).toMatchInlineSnapshot(` expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js (7:1) "./pages/hmr/about2.js (7:1)
Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`? Error: Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?
5 | div 5 | div
6 | ) 6 | )
> 7 | } > 7 | }
...@@ -434,7 +434,7 @@ export function runErrorRecoveryHmrTest(nextConfig: { ...@@ -434,7 +434,7 @@ export function runErrorRecoveryHmrTest(nextConfig: {
if (process.env.IS_TURBOPACK_TEST) { if (process.env.IS_TURBOPACK_TEST) {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(` expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./components/parse-error.xyz "./components/parse-error.xyz
Unknown module type Error: Unknown module type
This module doesn't have an associated type. Use a known file extension, or register a loader for it. 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" Read more: https://nextjs.org/docs/app/api-reference/next-config-js/turbo#webpack-loaders"
...@@ -514,7 +514,7 @@ export function runErrorRecoveryHmrTest(nextConfig: { ...@@ -514,7 +514,7 @@ export function runErrorRecoveryHmrTest(nextConfig: {
expect(next.normalizeTestDirContent(redboxSource)) expect(next.normalizeTestDirContent(redboxSource))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"./components/parse-error.js (3:1) "./components/parse-error.js (3:1)
Expression expected Error: Expression expected
1 | This 1 | This
2 | is 2 | is
> 3 | }}} > 3 | }}}
......
...@@ -505,7 +505,7 @@ describe('middleware - development errors', () => { ...@@ -505,7 +505,7 @@ describe('middleware - development errors', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./middleware.js (1:28) "source": "./middleware.js (1:28)
Expected '{', got '}' Error: Expected '{', got '}'
> 1 | export default function () } > 1 | export default function () }
| ^", | ^",
"stack": [], "stack": [],
...@@ -590,7 +590,7 @@ describe('middleware - development errors', () => { ...@@ -590,7 +590,7 @@ describe('middleware - development errors', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./middleware.js (1:28) "source": "./middleware.js (1:28)
Expected '{', got '}' Error: Expected '{', got '}'
> 1 | export default function () } > 1 | export default function () }
| ^", | ^",
"stack": [], "stack": [],
......
...@@ -16,7 +16,7 @@ describe('font-loader-in-document-error', () => { ...@@ -16,7 +16,7 @@ describe('font-loader-in-document-error', () => {
// TODO: Turbopack doesn't include pages/ // TODO: Turbopack doesn't include pages/
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(` expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./_document.js "./_document.js
next/font: error: Error: next/font: error:
Cannot be used within _document.js" Cannot be used within _document.js"
`) `)
} else if (process.env.NEXT_RSPACK) { } else if (process.env.NEXT_RSPACK) {
......
...@@ -16,7 +16,7 @@ import { getRedboxSource, waitForRedbox } from 'next-test-utils' ...@@ -16,7 +16,7 @@ import { getRedboxSource, waitForRedbox } from 'next-test-utils'
const error = await getRedboxSource(browser) const error = await getRedboxSource(browser)
expect(error).toMatchInlineSnapshot(` expect(error).toMatchInlineSnapshot(`
"./app/foo.tsx (2:14) "./app/foo.tsx (2:14)
TP1202 The commit hash is being inlined. Error: TP1202 The commit hash is being inlined.
1 | export function Foo() { 1 | export function Foo() {
> 2 | return <p>{process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA}</p> > 2 | return <p>{process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA}</p>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......
...@@ -26,7 +26,7 @@ describe('app dir - css', () => { ...@@ -26,7 +26,7 @@ describe('app dir - css', () => {
// css-loader does not report an error for this case // css-loader does not report an error for this case
expect(source).toMatchInlineSnapshot(` expect(source).toMatchInlineSnapshot(`
"./app/global.scss.css (45:1) "./app/global.scss.css (45:1)
Parsing CSS source code failed Error: Parsing CSS source code failed
43 | } 43 | }
44 | 44 |
> 45 | input.defaultCheckbox::before path { > 45 | input.defaultCheckbox::before path {
......
...@@ -34,7 +34,7 @@ describe('app-dir edge SSR invalid reexport', () => { ...@@ -34,7 +34,7 @@ describe('app-dir edge SSR invalid reexport', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/export/inherit/page.tsx (1:28) "source": "./app/export/inherit/page.tsx (1:28)
Next.js can't recognize the exported \`preferredRegion\` field in route. It mustn't be reexported. Error: Next.js can't recognize the exported \`preferredRegion\` field in route. It mustn't be reexported.
> 1 | export { default, runtime, preferredRegion } from '../basic/page' > 1 | export { default, runtime, preferredRegion } from '../basic/page'
| ^^^^^^^^^^^^^^^", | ^^^^^^^^^^^^^^^",
"stack": [], "stack": [],
......
...@@ -52,7 +52,7 @@ function filterToErrorHeaders(output: string): string { ...@@ -52,7 +52,7 @@ function filterToErrorHeaders(output: string): string {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/edge-with-layout/layout.tsx (1:14) "source": "./app/edge-with-layout/layout.tsx (1:14)
Route segment config "dynamic" is not compatible with \`nextConfig.cacheComponents\`. Please remove it. Error: Route segment config "dynamic" is not compatible with \`nextConfig.cacheComponents\`. Please remove it.
> 1 | export const dynamic = 'force-dynamic' > 1 | export const dynamic = 'force-dynamic'
| ^^^^^^^", | ^^^^^^^",
"stack": [], "stack": [],
......
...@@ -27,7 +27,7 @@ describe('app-dir - error-on-next-codemod-comment', () => { ...@@ -27,7 +27,7 @@ describe('app-dir - error-on-next-codemod-comment', () => {
if (process.env.IS_TURBOPACK_TEST) { if (process.env.IS_TURBOPACK_TEST) {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(` expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./app/page.tsx (2:2) "./app/page.tsx (2:2)
You have an unresolved @next/codemod comment "remove jsx of next line" that needs review. Error: You have an unresolved @next/codemod comment "remove jsx of next line" that needs review.
After review, either remove the comment if you made the necessary changes or replace "@next-codemod-error" with "@next-codemod-ignore" to bypass the build error if no action at this line can be taken. After review, either remove the comment if you made the necessary changes or replace "@next-codemod-error" with "@next-codemod-ignore" to bypass the build error if no action at this line can be taken.
1 | export default function Page() { 1 | export default function Page() {
> 2 | // @next-codemod-error remove jsx of next line > 2 | // @next-codemod-error remove jsx of next line
......
...@@ -46,7 +46,7 @@ describe('proxy-missing-export', () => { ...@@ -46,7 +46,7 @@ describe('proxy-missing-export', () => {
// TODO: Investigate why in dev-turbo, the error is shown in the browser console, not CLI output. // TODO: Investigate why in dev-turbo, the error is shown in the browser console, not CLI output.
if (process.env.IS_TURBOPACK_TEST && !isNextDev) { if (process.env.IS_TURBOPACK_TEST && !isNextDev) {
expect(cliOutput).toContain(`./proxy.ts expect(cliOutput).toContain(`./proxy.ts
Proxy is missing expected function export name Error: Proxy is missing expected function export name
${errorMessage}`) ${errorMessage}`)
} else { } else {
expect(cliOutput) expect(cliOutput)
...@@ -130,7 +130,7 @@ ${errorMessage}`) ...@@ -130,7 +130,7 @@ ${errorMessage}`)
// TODO: Investigate why in dev-turbo, the error is shown in the browser console, not CLI output. // TODO: Investigate why in dev-turbo, the error is shown in the browser console, not CLI output.
if (process.env.IS_TURBOPACK_TEST && !isNextDev) { if (process.env.IS_TURBOPACK_TEST && !isNextDev) {
expect(cliOutput).toContain(`./proxy.ts expect(cliOutput).toContain(`./proxy.ts
Proxy is missing expected function export name Error: Proxy is missing expected function export name
${errorMessage}`) ${errorMessage}`)
} else { } else {
expect(cliOutput) expect(cliOutput)
......
...@@ -27,7 +27,7 @@ describe('proxy-runtime', () => { ...@@ -27,7 +27,7 @@ describe('proxy-runtime', () => {
// TODO: Investigate why in dev-turbo, the error is shown in the browser console, not CLI output. // TODO: Investigate why in dev-turbo, the error is shown in the browser console, not CLI output.
if (process.env.IS_TURBOPACK_TEST && !isNextDev) { if (process.env.IS_TURBOPACK_TEST && !isNextDev) {
expect(stripAnsi(cliOutput)).toContain(`proxy.ts:3:14 expect(stripAnsi(cliOutput)).toContain(`proxy.ts:3:14
Next.js can't recognize the exported \`config\` field in route. Proxy does not support Edge runtime. Error: Next.js can't recognize the exported \`config\` field in route. Proxy does not support Edge runtime.
1 | export default function () {} 1 | export default function () {}
2 | 2 |
> 3 | export const config = { runtime: 'edge' } > 3 | export const config = { runtime: 'edge' }
......
...@@ -41,7 +41,7 @@ describe('Invalid Global CSS with Custom App', () => { ...@@ -41,7 +41,7 @@ describe('Invalid Global CSS with Custom App', () => {
if (isTurbopack) { if (isTurbopack) {
expect(errorSource).toMatchInlineSnapshot(` expect(errorSource).toMatchInlineSnapshot(`
"./pages/index.js "./pages/index.js
Global CSS cannot be imported from files other than your Custom <App>. Error: Global CSS cannot be imported from files other than your Custom <App>.
Due to the Global nature of stylesheets, and to avoid conflicts, Please move all first-party global CSS imports to pages/_app.js. Or convert the import to Component-Level CSS (CSS Modules). Due to the Global nature of stylesheets, and to avoid conflicts, Please move all first-party global CSS imports to pages/_app.js. Or convert the import to Component-Level CSS (CSS Modules).
Location: pages/index.js Location: pages/index.js
Import path: ../styles/global.scss Import path: ../styles/global.scss
......
...@@ -41,7 +41,7 @@ describe('Invalid Global CSS', () => { ...@@ -41,7 +41,7 @@ describe('Invalid Global CSS', () => {
if (isTurbopack) { if (isTurbopack) {
expect(errorSource).toMatchInlineSnapshot(` expect(errorSource).toMatchInlineSnapshot(`
"./pages/index.js "./pages/index.js
Global CSS cannot be imported from files other than your Custom <App>. Error: Global CSS cannot be imported from files other than your Custom <App>.
Due to the Global nature of stylesheets, and to avoid conflicts, Please move all first-party global CSS imports to pages/_app.js. Or convert the import to Component-Level CSS (CSS Modules). Due to the Global nature of stylesheets, and to avoid conflicts, Please move all first-party global CSS imports to pages/_app.js. Or convert the import to Component-Level CSS (CSS Modules).
Location: pages/index.js Location: pages/index.js
Import path: ../styles/global.scss Import path: ../styles/global.scss
......
...@@ -38,7 +38,7 @@ describe('CSS Import from node_modules', () => { ...@@ -38,7 +38,7 @@ describe('CSS Import from node_modules', () => {
if (isTurbopack) { if (isTurbopack) {
expect(errorSource).toMatchInlineSnapshot(` expect(errorSource).toMatchInlineSnapshot(`
"./styles/global.scss.css (1:9) "./styles/global.scss.css (1:9)
Module not found: Can't resolve 'nprogress/nprogress.css' Error: Module not found: Can't resolve 'nprogress/nprogress.css'
> 1 | @import 'nprogress/nprogress.css'; > 1 | @import 'nprogress/nprogress.css';
| ^ | ^
2 | 2 |
......
...@@ -41,7 +41,7 @@ describe('Valid and Invalid Global CSS with Custom App', () => { ...@@ -41,7 +41,7 @@ describe('Valid and Invalid Global CSS with Custom App', () => {
if (isTurbopack) { if (isTurbopack) {
expect(errorSource).toMatchInlineSnapshot(` expect(errorSource).toMatchInlineSnapshot(`
"./pages/index.js "./pages/index.js
Global CSS cannot be imported from files other than your Custom <App>. Error: Global CSS cannot be imported from files other than your Custom <App>.
Due to the Global nature of stylesheets, and to avoid conflicts, Please move all first-party global CSS imports to pages/_app.js. Or convert the import to Component-Level CSS (CSS Modules). Due to the Global nature of stylesheets, and to avoid conflicts, Please move all first-party global CSS imports to pages/_app.js. Or convert the import to Component-Level CSS (CSS Modules).
Location: pages/index.js Location: pages/index.js
Import path: ../styles/global.scss Import path: ../styles/global.scss
......
...@@ -26,7 +26,7 @@ describe('use-cache-segment-configs', () => { ...@@ -26,7 +26,7 @@ describe('use-cache-segment-configs', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/runtime/page.tsx (1:14) "source": "./app/runtime/page.tsx (1:14)
Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. Error: Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it.
> 1 | export const runtime = 'edge' > 1 | export const runtime = 'edge'
| ^^^^^^^", | ^^^^^^^",
"stack": [], "stack": [],
...@@ -78,9 +78,9 @@ describe('use-cache-segment-configs', () => { ...@@ -78,9 +78,9 @@ describe('use-cache-segment-configs', () => {
if (isTurbopack) { if (isTurbopack) {
expect(buildOutput).toMatchInlineSnapshot(` expect(buildOutput).toMatchInlineSnapshot(`
"Error: Turbopack build failed with 1 errors: "Error: Turbopack build failed with 1 error:
./app/runtime/page.tsx:1:14 ./app/runtime/page.tsx:1:14
Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. Error: Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it.
> 1 | export const runtime = 'edge' > 1 | export const runtime = 'edge'
| ^^^^^^^ | ^^^^^^^
2 | 2 |
......
...@@ -30,9 +30,9 @@ describe('use-cache-unknown-cache-kind', () => { ...@@ -30,9 +30,9 @@ describe('use-cache-unknown-cache-kind', () => {
if (isTurbopack) { if (isTurbopack) {
expect(buildOutput).toMatchInlineSnapshot(` expect(buildOutput).toMatchInlineSnapshot(`
"Error: Turbopack build failed with 1 errors: "Error: Turbopack build failed with 1 error:
./app/page.tsx:1:1 ./app/page.tsx:1:1
Unknown cache kind "custom". Please configure a cache handler for this kind in the \`cacheHandlers\` object in your Next.js config. Error: Unknown cache kind "custom". Please configure a cache handler for this kind in the \`cacheHandlers\` object in your Next.js config.
> 1 | 'use cache: custom' > 1 | 'use cache: custom'
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
2 | 2 |
...@@ -127,7 +127,7 @@ describe('use-cache-unknown-cache-kind', () => { ...@@ -127,7 +127,7 @@ describe('use-cache-unknown-cache-kind', () => {
if (isTurbopack) { if (isTurbopack) {
expect(errorSource).toMatchInlineSnapshot(` expect(errorSource).toMatchInlineSnapshot(`
"./app/page.tsx (1:1) "./app/page.tsx (1:1)
Unknown cache kind "custom". Please configure a cache handler for this kind in the \`cacheHandlers\` object in your Next.js config. Error: Unknown cache kind "custom". Please configure a cache handler for this kind in the \`cacheHandlers\` object in your Next.js config.
> 1 | 'use cache: custom' > 1 | 'use cache: custom'
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
2 | 2 |
......
...@@ -37,7 +37,7 @@ describe('swcPlugins', () => { ...@@ -37,7 +37,7 @@ describe('swcPlugins', () => {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/layout.js "source": "./app/layout.js
Failed to execute SWC plugin Error: Failed to execute SWC plugin
An unexpected error occurred when executing an SWC EcmaScript transform plugin. An unexpected error occurred when executing an SWC EcmaScript transform plugin.
This might be due to a version mismatch between the plugin and Next.js. https://plugins.swc.rs/ can help you find the correct plugin version to use. This might be due to a version mismatch between the plugin and Next.js. https://plugins.swc.rs/ can help you find the correct plugin version to use.
Failed to execute @swc/plugin-react-remove-properties Failed to execute @swc/plugin-react-remove-properties
...@@ -81,7 +81,7 @@ module.exports = { ...@@ -81,7 +81,7 @@ module.exports = {
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./ "source": "./
Module not found: Can't resolve '@swc/plugin-nonexistent' Error: Module not found: Can't resolve '@swc/plugin-nonexistent'
https://nextjs.org/docs/messages/module-not-found", https://nextjs.org/docs/messages/module-not-found",
"stack": [], "stack": [],
} }
......
...@@ -23,7 +23,7 @@ describe('transpile-packages-typescript-foreign', () => { ...@@ -23,7 +23,7 @@ describe('transpile-packages-typescript-foreign', () => {
if (process.env.IS_TURBOPACK_TEST) { if (process.env.IS_TURBOPACK_TEST) {
expect(next.cliOutput).toContain(`pkg/index.ts expect(next.cliOutput).toContain(`pkg/index.ts
Unknown module type Error: Unknown module type
This module doesn't have an associated type`) This module doesn't have an associated type`)
expect( expect(
next.cliOutput.match(/Unknown module type/g).length next.cliOutput.match(/Unknown module type/g).length
......
...@@ -113,7 +113,7 @@ describe('webpack-loader-parse-error (development)', () => { ...@@ -113,7 +113,7 @@ describe('webpack-loader-parse-error (development)', () => {
) )
expect(errorBlock).toMatchInlineSnapshot(` expect(errorBlock).toMatchInlineSnapshot(`
"⨯ ./app/data.broken.js:3:1 "⨯ ./app/data.broken.js:3:1
Expected '</', got '{' Error: Expected '</', got '{'
1 | // This file will be processed by broken-js-loader 1 | // This file will be processed by broken-js-loader
2 | // The loader will return invalid JavaScript with a source map 2 | // The loader will return invalid JavaScript with a source map
> 3 | export default function Data() { > 3 | export default function Data() {
...@@ -167,7 +167,7 @@ describe('webpack-loader-parse-error (development)', () => { ...@@ -167,7 +167,7 @@ describe('webpack-loader-parse-error (development)', () => {
) )
expect(errorBlock).toMatchInlineSnapshot(` expect(errorBlock).toMatchInlineSnapshot(`
"⨯ ./app/css-page/styles.broken.css:2:3 "⨯ ./app/css-page/styles.broken.css:2:3
Parsing CSS source code failed Error: Parsing CSS source code failed
1 | .page { 1 | .page {
> 2 | color: blue; > 2 | color: blue;
| ^ | ^
...@@ -218,7 +218,7 @@ describe('webpack-loader-parse-error (production)', () => { ...@@ -218,7 +218,7 @@ describe('webpack-loader-parse-error (production)', () => {
const jsError = extractErrorBlock(output, "Expected '</', got '{'") const jsError = extractErrorBlock(output, "Expected '</', got '{'")
expect(jsError).toMatchInlineSnapshot(` expect(jsError).toMatchInlineSnapshot(`
"./app/data.broken.js:3:1 "./app/data.broken.js:3:1
Expected '</', got '{' Error: Expected '</', got '{'
1 | // This file will be processed by broken-js-loader 1 | // This file will be processed by broken-js-loader
2 | // The loader will return invalid JavaScript with a source map 2 | // The loader will return invalid JavaScript with a source map
> 3 | export default function Data() { > 3 | export default function Data() {
...@@ -250,7 +250,7 @@ describe('webpack-loader-parse-error (production)', () => { ...@@ -250,7 +250,7 @@ describe('webpack-loader-parse-error (production)', () => {
) )
expect(cssError).toMatchInlineSnapshot(` expect(cssError).toMatchInlineSnapshot(`
"./app/css-page/styles.broken.css:5:15 "./app/css-page/styles.broken.css:5:15
Parsing CSS source code failed Error: Parsing CSS source code failed
3 | color: red 3 | color: red
4 | @@@ THIS IS NOT VALID CSS @@@; 4 | @@@ THIS IS NOT VALID CSS @@@;
> 5 | background: {{{ invalid > 5 | background: {{{ invalid
......
...@@ -22,9 +22,9 @@ import stripAnsi from 'strip-ansi' ...@@ -22,9 +22,9 @@ import stripAnsi from 'strip-ansi'
.trim() .trim()
expect(stripAnsi(output)).toMatchInlineSnapshot(` expect(stripAnsi(output)).toMatchInlineSnapshot(`
"Turbopack build encountered 1 warnings: "Turbopack build encountered 1 warning:
./app/join-cwd.js:4:10 ./app/join-cwd.js:4:10
Dynamic filesystem access causes tracing of the whole project Warning: Dynamic filesystem access causes tracing of the whole project
2 | 2 |
3 | export default function (f) { 3 | export default function (f) {
> 4 | return path.join(process.cwd(), f) > 4 | return path.join(process.cwd(), f)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment