fix(run): skip the cjs suggestion for mjs/mts modules (#26698)

Co-authored-by: David Sherret <dsherret@gmail.com>
This commit is contained in:
Mohammad Sulaiman 2025-03-05 19:29:41 +02:00 committed by Ryan Dahl
parent 2ddaafd762
commit 64a4003487
5 changed files with 28 additions and 0 deletions

View file

@ -309,6 +309,13 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec<FixSuggestion> {
|| msg.contains("exports is not defined") || msg.contains("exports is not defined")
|| msg.contains("require 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![ return vec![
FixSuggestion::info_multiline(&[ FixSuggestion::info_multiline(&[
cstr!("Deno supports CommonJS modules in <u>.cjs</> files, or when the closest"), cstr!("Deno supports CommonJS modules in <u>.cjs</> files, or when the closest"),

View file

@ -0,0 +1,5 @@
{
"args": "run --allow-read main.mts",
"exitCode": 1,
"output": "main.out"
}

View file

@ -0,0 +1,6 @@
function add(num1, num2) {
const result = num1 + num2;
return result;
}
module.exports = { add };

View file

@ -0,0 +1,5 @@
import * as a from "./a.cts";
console.log(a.add(1, 2));
module.isPreloading = true;

View file

@ -0,0 +1,5 @@
3
error: Uncaught (in promise) ReferenceError: module is not defined
module.isPreloading = true;
^
at file:///[WILDLINE]/main.mts:5:1