Merge pull request #19191 from Snuffleupagus/Node-legacy-warn

Print more warnings about potential problems in Node.js environments
This commit is contained in:
Tim van der Meij 2024-12-07 14:54:57 +01:00 committed by GitHub
commit 3f1d07a35e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,11 +26,10 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
); );
} }
if ( if (isNodeJS) {
typeof PDFJSDev !== "undefined" && if (typeof PDFJSDev === "undefined" || PDFJSDev.test("SKIP_BABEL")) {
!PDFJSDev.test("SKIP_BABEL") && warn("Please use the `legacy` build in Node.js environments.");
isNodeJS } else {
) {
let canvas; let canvas;
try { try {
const require = process const require = process
@ -42,7 +41,9 @@ if (
} catch (ex) { } catch (ex) {
warn(`Cannot load "@napi-rs/canvas" package: "${ex}".`); warn(`Cannot load "@napi-rs/canvas" package: "${ex}".`);
} }
} catch {} } catch (ex) {
warn(`Cannot access the \`require\` function: "${ex}".`);
}
if (!globalThis.DOMMatrix) { if (!globalThis.DOMMatrix) {
if (canvas?.DOMMatrix) { if (canvas?.DOMMatrix) {
@ -65,6 +66,7 @@ if (
warn("Cannot polyfill `Path2D`, rendering may be broken."); warn("Cannot polyfill `Path2D`, rendering may be broken.");
} }
} }
}
} }
async function fetchData(url) { async function fetchData(url) {