mirror of
https://github.com/denoland/deno.git
synced 2025-08-10 05:48:06 +00:00
fix(run): skip the cjs suggestion for mjs/mts modules (#26698)
Co-authored-by: David Sherret <dsherret@gmail.com>
This commit is contained in:
parent
2ddaafd762
commit
64a4003487
5 changed files with 28 additions and 0 deletions
|
@ -309,6 +309,13 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec<FixSuggestion> {
|
|||
|| 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 <u>.cjs</> files, or when the closest"),
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"args": "run --allow-read main.mts",
|
||||
"exitCode": 1,
|
||||
"output": "main.out"
|
||||
}
|
6
tests/specs/run/no_cjs_suggestion_mts_file/a.cts
Normal file
6
tests/specs/run/no_cjs_suggestion_mts_file/a.cts
Normal file
|
@ -0,0 +1,6 @@
|
|||
function add(num1, num2) {
|
||||
const result = num1 + num2;
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = { add };
|
5
tests/specs/run/no_cjs_suggestion_mts_file/main.mts
Normal file
5
tests/specs/run/no_cjs_suggestion_mts_file/main.mts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import * as a from "./a.cts";
|
||||
|
||||
console.log(a.add(1, 2));
|
||||
|
||||
module.isPreloading = true;
|
5
tests/specs/run/no_cjs_suggestion_mts_file/main.out
Normal file
5
tests/specs/run/no_cjs_suggestion_mts_file/main.out
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue