Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(terminal): Skip the cjs suggestion for mjs/mts modules #26698

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions runtime/fmt_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ fn format_js_error_inner(
}

fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec<FixSuggestion> {
if let Some(frame) = e.frames.first() {
if let Some(file_name) = &frame.file_name {
if file_name.ends_with(".mjs") || file_name.ends_with(".mts") {
return vec![];
}
}
}
if let Some(msg) = &e.message {
if msg.contains("module is not defined")
|| msg.contains("exports is not defined")
Expand Down
4 changes: 4 additions & 0 deletions tests/specs/fmt_errors/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"args": "run --unstable --allow-read main.mts",
"output": "main.out"
}
6 changes: 6 additions & 0 deletions tests/specs/fmt_errors/a.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function add(num1, num2) {
const result = num1 + num2;
return result;
}

module.exports = { add };
3 changes: 3 additions & 0 deletions tests/specs/fmt_errors/main.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as a from "./a.cts";

console.log(a.add(1, 2));
1 change: 1 addition & 0 deletions tests/specs/fmt_errors/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3