diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-10-16 00:25:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-15 23:25:24 +0000 |
commit | 40b1c42138c47e89eefa859cd36a9e3d62541e7b (patch) | |
tree | e4ab7cf2a9c369daf45c6e7b339fdc59dafde09b /runtime/fmt_errors.rs | |
parent | 82d13fd45b6fa8da5d390e26a349522e93811639 (diff) |
fix: improve suggestions and hints when using CommonJS modules (#26287)
Ref https://github.com/denoland/deno/issues/26225
Diffstat (limited to 'runtime/fmt_errors.rs')
-rw-r--r-- | runtime/fmt_errors.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/runtime/fmt_errors.rs b/runtime/fmt_errors.rs index 2d9d09a29..8476aab28 100644 --- a/runtime/fmt_errors.rs +++ b/runtime/fmt_errors.rs @@ -287,14 +287,20 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec<FixSuggestion> { if let Some(msg) = &e.message { if msg.contains("module is not defined") || msg.contains("exports is not defined") + || msg.contains("require is not defined") { return vec![ - FixSuggestion::info( - "Deno does not support CommonJS modules without `.cjs` extension.", - ), - FixSuggestion::hint( - "Rewrite this module to ESM or change the file extension to `.cjs`.", - ), + FixSuggestion::info_multiline(&[ + cstr!("Deno supports CommonJS modules in <u>.cjs</> files, or when there's a <u>package.json</>"), + cstr!("with <i>\"type\": \"commonjs\"</> option and <i>--unstable-detect-cjs</> flag is used.") + ]), + FixSuggestion::hint_multiline(&[ + "Rewrite this module to ESM,", + cstr!("or change the file extension to <u>.cjs</u>,"), + cstr!("or add <u>package.json</> next to the file with <i>\"type\": \"commonjs\"</> option"), + cstr!("and pass <i>--unstable-detect-cjs</> flag."), + ]), + FixSuggestion::hint("See https://docs.deno.com/go/commonjs for details"), ]; } else if msg.contains("openKv is not a function") { return vec![ |