Cloudflare Worker发布及本地开发时出现XMLHttpRequest构造函数错误的求助
Cloudflare Worker发布及本地开发时出现XMLHttpRequest构造函数错误的求助
大家好,我最近在开发Cloudflare Worker时碰到了个棘手的问题,想请教下各位大佬:
当我运行wrangler dev命令时,代码能正常编译,但尝试上传的时候就会抛出错误;甚至我打错命令成warngler dev时,也会出现类似的报错。
错误详情
Uncaught TypeError: globalThis.XMLHttpRequest is not a constructor at index.js:4699:11 in checkTypeSupport at index.js:4720:38 in ../../usr/local/lib/node_modules/wrangler/node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js at index.js:15:56 in __init at index.js:8501:5 in ../../usr/local/lib/node_modules/wrangler/node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/request.js at index.js:15:56 in __init at index.js:8718:5 in node-modules-polyfills:http at index.js:15:56 in __init at index.js:8822:21 in node-modules-polyfills-commonjs:http at index.js:18:51 in __require2 at index.js:16698:16 in node_modules/firebase-admin/lib/utils/api-request.js [code: 10021] If you think this is a bug, please open an issue at: https://github.com/cloudflare/workers-sdk/issues/new/choose
我的Webpack配置
我用Webpack来编译代码,单独运行Webpack编译是完全正常的,我的webpack.config.js配置如下:
const webpack = require("webpack"); var fs = require('fs'); module.exports = { target: "node", entry: "./src/index.js", mode: "production", output: { path: path.resolve(__dirname, 'dist'), filename: "worker.js" }, resolve: { fallback: { // browser/worker polyfills required to replace Node libraries used by the jsC8 SDK "url": require.resolve("url"), "path": require.resolve("path-browserify"), "crypto": require.resolve("crypto-browserify"), "assert": require.resolve("assert/") } } };
有没有朋友遇到过类似的问题?或者能给我一些排查方向的建议?万分感谢🙏
备注:内容来源于stack exchange,提问作者Ava
相关产品推荐
相关产品推荐

