mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix: add hint for missing document
global in terminal error (#26218)
This came up on Discord as a question so I thought it's worth adding a hint for this as it might be a common pitfall. --------- Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
This commit is contained in:
parent
3065dadea3
commit
ee904ec06c
11 changed files with 67 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1997,6 +1997,7 @@ dependencies = [
|
||||||
name = "deno_runtime"
|
name = "deno_runtime"
|
||||||
version = "0.180.0"
|
version = "0.180.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"color-print",
|
||||||
"deno_ast",
|
"deno_ast",
|
||||||
"deno_broadcast_channel",
|
"deno_broadcast_channel",
|
||||||
"deno_cache",
|
"deno_cache",
|
||||||
|
|
|
@ -106,6 +106,7 @@ cbc = { version = "=0.1.2", features = ["alloc"] }
|
||||||
# Note: Do not use the "clock" feature of chrono, as it links us to CoreFoundation on macOS.
|
# Note: Do not use the "clock" feature of chrono, as it links us to CoreFoundation on macOS.
|
||||||
# Instead use util::time::utc_now()
|
# Instead use util::time::utc_now()
|
||||||
chrono = { version = "0.4", default-features = false, features = ["std", "serde"] }
|
chrono = { version = "0.4", default-features = false, features = ["std", "serde"] }
|
||||||
|
color-print = "0.3.5"
|
||||||
console_static_text = "=0.8.1"
|
console_static_text = "=0.8.1"
|
||||||
dashmap = "5.5.3"
|
dashmap = "5.5.3"
|
||||||
data-encoding = "2.3.3"
|
data-encoding = "2.3.3"
|
||||||
|
|
|
@ -94,7 +94,7 @@ chrono = { workspace = true, features = ["now"] }
|
||||||
clap = { version = "=4.5.16", features = ["env", "string", "wrap_help", "error-context"] }
|
clap = { version = "=4.5.16", features = ["env", "string", "wrap_help", "error-context"] }
|
||||||
clap_complete = "=4.5.24"
|
clap_complete = "=4.5.24"
|
||||||
clap_complete_fig = "=4.5.2"
|
clap_complete_fig = "=4.5.2"
|
||||||
color-print = "0.3.5"
|
color-print.workspace = true
|
||||||
console_static_text.workspace = true
|
console_static_text.workspace = true
|
||||||
dashmap.workspace = true
|
dashmap.workspace = true
|
||||||
data-encoding.workspace = true
|
data-encoding.workspace = true
|
||||||
|
|
|
@ -100,6 +100,7 @@ deno_websocket.workspace = true
|
||||||
deno_webstorage.workspace = true
|
deno_webstorage.workspace = true
|
||||||
node_resolver = { workspace = true, features = ["sync"] }
|
node_resolver = { workspace = true, features = ["sync"] }
|
||||||
|
|
||||||
|
color-print.workspace = true
|
||||||
dlopen2.workspace = true
|
dlopen2.workspace = true
|
||||||
encoding_rs.workspace = true
|
encoding_rs.workspace = true
|
||||||
fastwebsockets.workspace = true
|
fastwebsockets.workspace = true
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||||
//! This mod provides DenoError to unify errors across Deno.
|
//! This mod provides DenoError to unify errors across Deno.
|
||||||
|
use color_print::cstr;
|
||||||
use deno_core::error::format_frame;
|
use deno_core::error::format_frame;
|
||||||
use deno_core::error::JsError;
|
use deno_core::error::JsError;
|
||||||
use deno_terminal::colors::cyan;
|
use deno_terminal::colors::cyan;
|
||||||
|
@ -367,6 +368,16 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec<FixSuggestion> {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
} else if msg.contains("document is not defined") {
|
||||||
|
return vec![
|
||||||
|
FixSuggestion::info(cstr!(
|
||||||
|
"<u>document</> global is not available in Deno."
|
||||||
|
)),
|
||||||
|
FixSuggestion::hint_multiline(&[
|
||||||
|
cstr!("Use a library like <u>happy-dom</>, <u>deno_dom</>, <u>linkedom</> or <u>JSDom</>"),
|
||||||
|
cstr!("and setup the <u>document</> global according to the library documentation."),
|
||||||
|
]),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
9
tests/specs/run/document/__test__.jsonc
Normal file
9
tests/specs/run/document/__test__.jsonc
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"tests": {
|
||||||
|
"document": {
|
||||||
|
"args": "run document.js",
|
||||||
|
"exitCode": 1,
|
||||||
|
"output": "document.out"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
tests/specs/run/document/document.js
Normal file
1
tests/specs/run/document/document.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
document.querySelector("div");
|
8
tests/specs/run/document/document.out
Normal file
8
tests/specs/run/document/document.out
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
error: Uncaught (in promise) ReferenceError: document is not defined
|
||||||
|
document.querySelector("div");
|
||||||
|
^
|
||||||
|
at [WILDCARD]document.js:1:1
|
||||||
|
|
||||||
|
info: document global is not available in Deno.
|
||||||
|
hint: Use a library like happy-dom, deno_dom, linkedom or JSDom
|
||||||
|
and setup the document global according to the library documentation.
|
9
tests/specs/test/document/__test__.jsonc
Normal file
9
tests/specs/test/document/__test__.jsonc
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"tests": {
|
||||||
|
"document": {
|
||||||
|
"args": "test document_test.js",
|
||||||
|
"exitCode": 1,
|
||||||
|
"output": "document_test.out"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
tests/specs/test/document/document_test.js
Normal file
3
tests/specs/test/document/document_test.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Deno.test("document query selector", () => {
|
||||||
|
document.querySelector("div");
|
||||||
|
});
|
22
tests/specs/test/document/document_test.out
Normal file
22
tests/specs/test/document/document_test.out
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
running 1 test from ./document_test.js
|
||||||
|
document query selector ... FAILED [WILDCARD]
|
||||||
|
|
||||||
|
ERRORS
|
||||||
|
|
||||||
|
document query selector => ./document_test.js:1:6
|
||||||
|
error: ReferenceError: document is not defined
|
||||||
|
document.querySelector("div");
|
||||||
|
^
|
||||||
|
at [WILDCARD]document_test.js:2:3
|
||||||
|
|
||||||
|
info: document global is not available in Deno.
|
||||||
|
hint: Use a library like happy-dom, deno_dom, linkedom or JSDom
|
||||||
|
and setup the document global according to the library documentation.
|
||||||
|
|
||||||
|
FAILURES
|
||||||
|
|
||||||
|
document query selector => ./document_test.js:1:6
|
||||||
|
|
||||||
|
FAILED | 0 passed | 1 failed ([WILDCARD])
|
||||||
|
|
||||||
|
error: Test failed
|
Loading…
Reference in a new issue