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
kian14mo 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
MrDiamondOP14mo 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
kian14mo ago
Can you show your imports in the Worker? There shoudn't be a @hono/node-server.
MrDiamond
MrDiamondOP14mo 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
kian14mo ago
fs isn't available since Workers don't have a filesystem, there is no disk.
MrDiamond
MrDiamondOP14mo 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