javascript “未捕获的类型错误:globalThis.XMLHttpRequest is not a constructor”当发布cloudflare worker时

wsewodh2  于 2023-05-21  发布在  Java
关注(0)|答案(1)|浏览(305)

当我运行“牧马人开发”,它编译,试图上传,然后给我这个错误。使用“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.config.js如下。Webpack自己编译就可以了。

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/")
    }
  }
};

任何帮助将不胜感激:D

91zkwejq

91zkwejq1#

原来Firebase节点模块与wranglers不兼容。:(

相关问题