diff --git a/cli/main.rs b/cli/main.rs index a7e1c8342e..84c3704ca1 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -380,6 +380,11 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec<FixSuggestion> { "Run again with `--unstable-broadcast-channel` flag to enable this API.", ), ]; + } else if msg.contains("window is not defined") { + return vec![ + FixSuggestion::info("window global is not available in Deno 2."), + FixSuggestion::hint("Replace `window` with `globalThis`."), + ]; } } diff --git a/tests/specs/run/window/__test__.jsonc b/tests/specs/run/window/__test__.jsonc new file mode 100644 index 0000000000..1ee4449b57 --- /dev/null +++ b/tests/specs/run/window/__test__.jsonc @@ -0,0 +1,19 @@ +{ + "tests": { + "window1": { + "args": "run window1.js", + "exitCode": 1, + "output": "window1.out" + }, + "window2": { + "args": "run window2.js", + "exitCode": 1, + "output": "window2.out" + }, + "window3": { + "args": "run window3.js", + "exitCode": 1, + "output": "window3.out" + } + } +} diff --git a/tests/specs/run/window/window1.js b/tests/specs/run/window/window1.js new file mode 100644 index 0000000000..a480d4c2c6 --- /dev/null +++ b/tests/specs/run/window/window1.js @@ -0,0 +1 @@ +"TextEncoder" in window; diff --git a/tests/specs/run/window/window1.out b/tests/specs/run/window/window1.out new file mode 100644 index 0000000000..4e16744252 --- /dev/null +++ b/tests/specs/run/window/window1.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: window is not defined +"TextEncoder" in window; + ^ + at [WILDCARD]window1.js:1:18 + + info: window global is not available in Deno 2. + hint: Replace `window` with `globalThis`. diff --git a/tests/specs/run/window/window2.js b/tests/specs/run/window/window2.js new file mode 100644 index 0000000000..0fdf5dcb98 --- /dev/null +++ b/tests/specs/run/window/window2.js @@ -0,0 +1 @@ +window.atob; diff --git a/tests/specs/run/window/window2.out b/tests/specs/run/window/window2.out new file mode 100644 index 0000000000..7d00cd7ed1 --- /dev/null +++ b/tests/specs/run/window/window2.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: window is not defined +window.atob; +^ + at [WILDCARD]window2.js:1:1 + + info: window global is not available in Deno 2. + hint: Replace `window` with `globalThis`. diff --git a/tests/specs/run/window/window3.js b/tests/specs/run/window/window3.js new file mode 100644 index 0000000000..24fa32b5ac --- /dev/null +++ b/tests/specs/run/window/window3.js @@ -0,0 +1 @@ +window.navigator; diff --git a/tests/specs/run/window/window3.out b/tests/specs/run/window/window3.out new file mode 100644 index 0000000000..9a157975f8 --- /dev/null +++ b/tests/specs/run/window/window3.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: window is not defined +window.navigator; +^ + at [WILDCARD]window3.js:1:1 + + info: window global is not available in Deno 2. + hint: Replace `window` with `globalThis`.