globalThis.XMLHttpRequest is not a constructor

I am trying to use wrangler deploy to deploy my app, but it keeps giving this error. I am not using XMLHttpRequest afaik. Dependencies:
"devDependencies": {
"@types/express": "^4.17.20",
"@types/node": "^20.8.7",
"nodemon": "^3.0.1",
"tsx": "^3.14.0",
"typescript": "^5.2.2",
"wrangler": "^3.14.0"
},
"dependencies": {
"canvas": "^2.11.2",
"define-data-property": "^1.1.1",
"discord-interactions": "^3.4.0",
"dotenv": "^16.3.1",
"express": "^4.18.2"
}
"devDependencies": {
"@types/express": "^4.17.20",
"@types/node": "^20.8.7",
"nodemon": "^3.0.1",
"tsx": "^3.14.0",
"typescript": "^5.2.2",
"wrangler": "^3.14.0"
},
"dependencies": {
"canvas": "^2.11.2",
"define-data-property": "^1.1.1",
"discord-interactions": "^3.4.0",
"dotenv": "^16.3.1",
"express": "^4.18.2"
}
wrangler.toml
name = "discord-bot"
main = "./dist/index.js"
compatibility_date = "2023-10-21"
node_compat = true
name = "discord-bot"
main = "./dist/index.js"
compatibility_date = "2023-10-21"
node_compat = true
Full error
Uncaught TypeError: globalThis.XMLHttpRequest is not a constructor
at worker.js:31375:13 in checkTypeSupport
at worker.js:31397:40 in
node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js
at worker.js:15:58 in __init
at worker.js:31662:7 in node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/request.js
at worker.js:15:58 in __init
at worker.js:31880:7 in node-modules-polyfills:http
at worker.js:15:58 in __init
at worker.js:32000:23 in node-modules-polyfills-commonjs:http
at worker.js:18:52 in __require2
at worker.js:32019:18 in node_modules/methods/index.js
[code: 10021]
Uncaught TypeError: globalThis.XMLHttpRequest is not a constructor
at worker.js:31375:13 in checkTypeSupport
at worker.js:31397:40 in
node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js
at worker.js:15:58 in __init
at worker.js:31662:7 in node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/request.js
at worker.js:15:58 in __init
at worker.js:31880:7 in node-modules-polyfills:http
at worker.js:15:58 in __init
at worker.js:32000:23 in node-modules-polyfills-commonjs:http
at worker.js:18:52 in __require2
at worker.js:32019:18 in node_modules/methods/index.js
[code: 10021]
6 Replies
kian
kian8mo ago
Workers only support fetch, not XHR. You probably have a dependency using it. rollup-plugin-node-polyfills meowthinking - that shouldn't be throwing it. It hasn't been updated for ~4 years. It sounds like you have some code which is trying to load the http NodeJS module.
MrDiamond
MrDiamond8mo ago
I would assume express uses XHR/http then, do you know of any alternatives? They send interactions with my bot to my /interactions endpoint, after that I can handle it and respond Got the hono server working, but now publish is throwing a different error:
node_modules/@hono/node-server/dist/listener.js:25:30: ERROR: Could not resolve
"node:stream/promises"
node_modules/@hono/node-server/dist/listener.js:25:30: ERROR: Could not resolve
"node:stream/promises"
The package "node:stream/promises" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
The package "node:stream/promises" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
There is also this, but I don't know where to specify this option.
kian
kian8mo ago
Can you show your imports in the Worker? There shoudn't be a @hono/node-server.
MrDiamond
MrDiamond8mo ago
Well I cant serve the server without it afaik Ok nvm, I just needed to export default app Uncaught TypeError: fs_1.default.readdirSync is not a function how much code do i need to replace??
kian
kian8mo ago
fs isn't available since Workers don't have a filesystem, there is no disk.
MrDiamond
MrDiamond8mo ago
I switched to render so I don't have to deal with all these trade-offs
Want results from more Discord servers?
Add your server
More Posts
worker functions locally, but not when deployedIn production this code fails to retrieve data like 80% of the time. I added some debugging code to Issue with npx create-cloudflare-cli --template chatgpt-plugin <PROJECT_NAME>Hello cloudfare community, I've been trying to set up a new Cloudflare Workers project using the counable to add Pages custom domain when it includes ü: (Code: 8000000)Hi, I want to add the custom domain shop.züripeople.ch (shop.xn--zripeople-q9a.ch) to zpshop.pages.dHow to set `logpush=true` without `wrangler.toml`I use nuxt.js which automatically builds the app for cloudflare pages. This is great, however I do nSocket server inside of Sveltekit Pages appHey guys I'm building a sveltekit app with CF Pages, I need to make a websocket server for handling Turnstile captcha not workingalways invalid captcha when captcha is completed succesfully. I had this problem that it returned InUsing Durable Objects in Dev EnvironmentIn my `wrangler.toml` file I have this structure: ``` [env.dev] vars = { ENVIRONMENT = "dev" } [enAll websites in cloudflare account getting ratelimited incase of DDOS attackHi, I own multiple domains and manage multiple services for relatively small businesses / hobby projIs it a good idea to use static sites for images instead of cloudflare images?Is it a good idea to use static sites for images instead of cloudflare images?Zero Trust Access Application Bookmarks - Apply Policies [feature request?]I'd like to apply policies to bookmarks saved in the Zero Trust Access Applications list. I am aware