diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..01b7e33 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +**/* \ No newline at end of file diff --git a/polyfill/fetch.mjs b/polyfill/fetch.mjs index ec96343..6b41c60 100644 --- a/polyfill/fetch.mjs +++ b/polyfill/fetch.mjs @@ -215,9 +215,14 @@ export async function fetch(resource, options = {}) { }), ]); case "Node.js": { - const nodeFetch = globalThis.fetch ? globalThis.fetch : require("node-fetch"); - const fetchCookie = globalThis.fetchCookie ? globalThis.fetchCookie : require("fetch-cookie").default; - const fetch = fetchCookie(nodeFetch); + const fetch = globalThis.fetch ?? (() => { + try { + return require("fetch-cookie").default(require("node-fetch")); + } catch { + return undefined; + } + })(); + if (!fetch) break; // 转换请求参数 resource.timeout = resource.timeout * 1000; resource.redirect = resource.redirection ? "follow" : "manual";