diff --git a/runtime/fmt_errors.rs b/runtime/fmt_errors.rs index 3bde37bbe2..e7294ca3f6 100644 --- a/runtime/fmt_errors.rs +++ b/runtime/fmt_errors.rs @@ -309,6 +309,13 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec { || msg.contains("exports is not defined") || msg.contains("require is not defined") { + if let Some(file_name) = + e.frames.first().and_then(|f| f.file_name.as_ref()) + { + if file_name.ends_with(".mjs") || file_name.ends_with(".mts") { + return vec![]; + } + } return vec![ FixSuggestion::info_multiline(&[ cstr!("Deno supports CommonJS modules in .cjs files, or when the closest"), diff --git a/tests/specs/run/no_cjs_suggestion_mts_file/__test__.jsonc b/tests/specs/run/no_cjs_suggestion_mts_file/__test__.jsonc new file mode 100644 index 0000000000..e4f44474c4 --- /dev/null +++ b/tests/specs/run/no_cjs_suggestion_mts_file/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "run --allow-read main.mts", + "exitCode": 1, + "output": "main.out" +} diff --git a/tests/specs/run/no_cjs_suggestion_mts_file/a.cts b/tests/specs/run/no_cjs_suggestion_mts_file/a.cts new file mode 100644 index 0000000000..636d99af3a --- /dev/null +++ b/tests/specs/run/no_cjs_suggestion_mts_file/a.cts @@ -0,0 +1,6 @@ +function add(num1, num2) { + const result = num1 + num2; + return result; +} + +module.exports = { add }; diff --git a/tests/specs/run/no_cjs_suggestion_mts_file/main.mts b/tests/specs/run/no_cjs_suggestion_mts_file/main.mts new file mode 100644 index 0000000000..cf256e315a --- /dev/null +++ b/tests/specs/run/no_cjs_suggestion_mts_file/main.mts @@ -0,0 +1,5 @@ +import * as a from "./a.cts"; + +console.log(a.add(1, 2)); + +module.isPreloading = true; diff --git a/tests/specs/run/no_cjs_suggestion_mts_file/main.out b/tests/specs/run/no_cjs_suggestion_mts_file/main.out new file mode 100644 index 0000000000..d775a4b800 --- /dev/null +++ b/tests/specs/run/no_cjs_suggestion_mts_file/main.out @@ -0,0 +1,5 @@ +3 +error: Uncaught (in promise) ReferenceError: module is not defined +module.isPreloading = true; +^ + at file:///[WILDLINE]/main.mts:5:1