@discordjs/rest: TypeError: Super expression must either be null or a function

I use @discordjs/rest (2.6.0) to post to my server once a day. Yesterday, I upgraded my project's dependencies. @vladfrangu/async_event_emitter was updated from 2.4.6 to 2.4.7. Today, posts fail with TypeError: Super expression must either be null or a function in @vladfrangu/async_event_emitter/node_modules/node-inspect-extracted/dist/inspect.js:2:44522 Anyone else seeing this? Guess I should pin async_event_emitter to 2.4.6?
64 Replies
d.js toolkit
d.js toolkit4w ago
Matthew
MatthewOP4w ago
node is 22.16.0, and it's failing both locally and in production (Cloudflare Workers) full code is
const { REST } = await import("@discordjs/rest")

const rest = new REST({ version: "10" }).setToken(env.DISCORD_TOKEN)

const response = await rest.post(`/channels/${DISCORD_CHANNELID}/threads`, {
body: {
name: "foo",
message: { content: "bar" },
auto_archive_duration: 10080, // one week
},
})
const { REST } = await import("@discordjs/rest")

const rest = new REST({ version: "10" }).setToken(env.DISCORD_TOKEN)

const response = await rest.post(`/channels/${DISCORD_CHANNELID}/threads`, {
body: {
name: "foo",
message: { content: "bar" },
auto_archive_duration: 10080, // one week
},
})
Mafia
Mafia4w ago
what type is the DISCORD_CHANNELID?
Matthew
MatthewOP4w ago
string.
Mafia
Mafia4w ago
should clarify what is the channel type
Matthew
MatthewOP4w ago
overriding the async emitter package to 2.4.6 fixed the issue for me Duh sorry. It's a forum channel On phone rn, can investigate further on laptop if that's useful
vladdy
vladdy4w ago
yes please
Mafia
Mafia4w ago
I was unable to replicate here are my dependencies
dependencies:
@discordjs/rest 2.6.0
├── @discordjs/collection 2.1.1
├── @discordjs/util 1.1.1
├── @sapphire/async-queue 1.5.5
├── @sapphire/snowflake 3.5.5
├── @vladfrangu/async_event_emitter 2.4.7
├── discord-api-types 0.38.31
├── magic-bytes.js 1.12.1
├── tslib 2.8.1
└── undici 6.21.3
discord-api-types 0.38.31
dependencies:
@discordjs/rest 2.6.0
├── @discordjs/collection 2.1.1
├── @discordjs/util 1.1.1
├── @sapphire/async-queue 1.5.5
├── @sapphire/snowflake 3.5.5
├── @vladfrangu/async_event_emitter 2.4.7
├── discord-api-types 0.38.31
├── magic-bytes.js 1.12.1
├── tslib 2.8.1
└── undici 6.21.3
discord-api-types 0.38.31
Matthew
MatthewOP4w ago
I can't replicate in a fresh repo, will try adding stuff from real codebase until something breaks
vladdy
vladdy4w ago
yes pls maybe its even your wrangler config or at least the stacktrace you're getting
Matthew
MatthewOP4w ago
and here is my package.json in case useful
{
"name": "@catfishing/tasks",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "wrangler dev --test-scheduled --ip 0.0.0.0 --port 8787 --persist-to=../.persist",
"cf-typegen": "wrangler types"
},
"devDependencies": {
"@types/node": "^24.9.1",
"typescript": "^5.9.3",
"wrangler": "^4.45.0"
},
"packageManager": "pnpm@10.11.1+sha512.e519b9f7639869dc8d5c3c5dfef73b3f091094b0a006d7317353c72b124e80e1afd429732e28705ad6bfa1ee879c1fce46c128ccebd3192101f43dd67c667912",
"dependencies": {
"@atproto/api": "^0.15.27",
"@catfishing/common": "workspace:*",
"@discordjs/rest": "^2.6.0",
"@sentry/cloudflare": "^9.46.0",
"cloudflare": "^5.2.0",
"masto": "^7.3.0",
"valibot": "^1.1.0"
}
}
{
"name": "@catfishing/tasks",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "wrangler dev --test-scheduled --ip 0.0.0.0 --port 8787 --persist-to=../.persist",
"cf-typegen": "wrangler types"
},
"devDependencies": {
"@types/node": "^24.9.1",
"typescript": "^5.9.3",
"wrangler": "^4.45.0"
},
"packageManager": "pnpm@10.11.1+sha512.e519b9f7639869dc8d5c3c5dfef73b3f091094b0a006d7317353c72b124e80e1afd429732e28705ad6bfa1ee879c1fce46c128ccebd3192101f43dd67c667912",
"dependencies": {
"@atproto/api": "^0.15.27",
"@catfishing/common": "workspace:*",
"@discordjs/rest": "^2.6.0",
"@sentry/cloudflare": "^9.46.0",
"cloudflare": "^5.2.0",
"masto": "^7.3.0",
"valibot": "^1.1.0"
}
}
vladdy
vladdy4w ago
well that stracktrace is not useful but it sounds like you repro'd?
Matthew
MatthewOP4w ago
#:schema node_modules/wrangler/config-schema.json
name = "catfishing-tasks"
main = "src/index.ts"
compatibility_date = "2024-12-30"
compatibility_flags = ["nodejs_compat"]

workers_dev = false
preview_urls = false
send_metrics = false

routes = [{ pattern = "foo", custom_domain = true }]

[observability]
enabled = true

[triggers]
crons = [ "*/5 * * * *", "0 0 * * *", "0 10 * * *" ]

[[d1_databases]]
binding = "DB" # Should match preview_database_id
database_name = "catfishing-us"
database_id = "foo"
preview_database_id = "DB" # Required for Pages local development

[[r2_buckets]]
binding = "R2_STATIC"
bucket_name = "foo"

[vars]
PUBLIC_SENTRY_DSN = "foo"
#:schema node_modules/wrangler/config-schema.json
name = "catfishing-tasks"
main = "src/index.ts"
compatibility_date = "2024-12-30"
compatibility_flags = ["nodejs_compat"]

workers_dev = false
preview_urls = false
send_metrics = false

routes = [{ pattern = "foo", custom_domain = true }]

[observability]
enabled = true

[triggers]
crons = [ "*/5 * * * *", "0 0 * * *", "0 10 * * *" ]

[[d1_databases]]
binding = "DB" # Should match preview_database_id
database_name = "catfishing-us"
database_id = "foo"
preview_database_id = "DB" # Required for Pages local development

[[r2_buckets]]
binding = "R2_STATIC"
bucket_name = "foo"

[vars]
PUBLIC_SENTRY_DSN = "foo"
vladdy
vladdy4w ago
it shouldn't tho the inspect module is bundled INTO aee not a node_modules dep
Matthew
MatthewOP4w ago
i haven't time to create a minimal repository that reproduces the erro sorry, but in my actual project I hit the error every time with async_emitter 2.4.7. both in cloudlfare, and localhost
vladdy
vladdy4w ago
does it trigger solely when you import discordjs/rest can you test that pls bc i need to know if its that or when an error event is emitted i do wonder if wrangler is messing smth up I also dont understand why your stack trace mentions an internal node_modules when one shouldn't exist
Matthew
MatthewOP4w ago
const { REST } = await import("@discordjs/rest")

const rest = new REST({ version: "10" }).setToken(env.DISCORD_TOKEN) // FAILS ON THIS LINE

const discordPostId = await attempt(() => post(rest, day))
console.log(`Submitted post for day ${day}: ${discordPostId}`)
const { REST } = await import("@discordjs/rest")

const rest = new REST({ version: "10" }).setToken(env.DISCORD_TOKEN) // FAILS ON THIS LINE

const discordPostId = await attempt(() => post(rest, day))
console.log(`Submitted post for day ${day}: ${discordPostId}`)
vladdy
vladdy4w ago
interesting humor me
const { REST } = await import("@discordjs/rest")

const rest = new REST({ version: "10" })
const { REST } = await import("@discordjs/rest")

const rest = new REST({ version: "10" })
does this throw
Matthew
MatthewOP4w ago
having said that, maybe js is smart enough to skip the import if REST is unused? (not an expert here)
vladdy
vladdy4w ago
i wonder if this is just wrangler messing smth up hardcore
Matthew
MatthewOP4w ago
yes this throws
vladdy
vladdy4w ago
fascinating
Matthew
MatthewOP4w ago
other random things, probably not useful: - this is one project in a monorepo that i'm managing with pnpm workspaces. no other projects use discordjs - to date, 100% of the time something weird has happened, it has been @sentry/cloudflare's fault
vladdy
vladdy4w ago
can you override aee with version 2.4.8-1.0 and lmk if it still errors?
Matthew
MatthewOP4w ago
- i added "overrides": { "aee": "2.4.8-1.0" } - deleted node_modules - ran pnpm install -r - still errors
vladdy
vladdy4w ago
well the module name is not aee its @vladfrangu/async_event_emitter
Matthew
MatthewOP4w ago
😂 one second still errors
vladdy
vladdy4w ago
and if you nuke the sentry thing also can you ll /home/foo/projects/foo/foo/node_modules/.pnpm/@vladfrangu+async_event_emitter@2.4.7 ofc adjusted for correct version
Matthew
MatthewOP4w ago
no such directory. but ll node_modules/.pnpm/@vladfrangu+async_event_emitter@2.4.8-1.0/ reports node_modules
vladdy
vladdy4w ago
what the everloving fuck
Matthew
MatthewOP4w ago
lmk if you want me to undo the override and retry 2.4.7
vladdy
vladdy4w ago
dare i ask why the everloving fuck can you show me the package.json with 2.4.7 pls
Matthew
MatthewOP4w ago
just checking I'm doing the right thing - I still have your 2.4.8.-1.0 override in place will undo it now have removed the override, and ll node_modules/.pnpm/@vladfrangu+async_event_emitter@2.4.7 now reports node_modules package.json for project
{
"name": "@catfishing/tasks",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "wrangler dev --test-scheduled --ip 0.0.0.0 --port 8787 --persist-to=../.persist",
"cf-typegen": "wrangler types"
},
"devDependencies": {
"@types/node": "^24.9.1",
"typescript": "^5.9.3",
"wrangler": "^4.45.0"
},
"packageManager": "pnpm@10.11.1+sha512.e519b9f7639869dc8d5c3c5dfef73b3f091094b0a006d7317353c72b124e80e1afd429732e28705ad6bfa1ee879c1fce46c128ccebd3192101f43dd67c667912",
"dependencies": {
"@atproto/api": "^0.15.27",
"@catfishing/common": "workspace:*",
"@discordjs/rest": "^2.6.0",
"@sentry/cloudflare": "^9.46.0",
"cloudflare": "^5.2.0",
"masto": "^7.3.0",
"valibot": "^1.1.0"
}
}
{
"name": "@catfishing/tasks",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "wrangler dev --test-scheduled --ip 0.0.0.0 --port 8787 --persist-to=../.persist",
"cf-typegen": "wrangler types"
},
"devDependencies": {
"@types/node": "^24.9.1",
"typescript": "^5.9.3",
"wrangler": "^4.45.0"
},
"packageManager": "pnpm@10.11.1+sha512.e519b9f7639869dc8d5c3c5dfef73b3f091094b0a006d7317353c72b124e80e1afd429732e28705ad6bfa1ee879c1fce46c128ccebd3192101f43dd67c667912",
"dependencies": {
"@atproto/api": "^0.15.27",
"@catfishing/common": "workspace:*",
"@discordjs/rest": "^2.6.0",
"@sentry/cloudflare": "^9.46.0",
"cloudflare": "^5.2.0",
"masto": "^7.3.0",
"valibot": "^1.1.0"
}
}
package.json for root of monorepo
{
"pnpm": {
"onlyBuiltDependencies": [
"@sentry/cli",
"core-js",
"esbuild",
"sharp",
"svelte-preprocess",
"workerd"
]
},
"packageManager": "pnpm@10.11.1+sha512.e519b9f7639869dc8d5c3c5dfef73b3f091094b0a006d7317353c72b124e80e1afd429732e28705ad6bfa1ee879c1fce46c128ccebd3192101f43dd67c667912",
"devDependencies": {
"concurrently": "^9.2.1",
"prettier": "^3.6.2",
"prettier-plugin-organize-imports": "^4.3.0",
"prettier-plugin-svelte": "^3.4.0",
"prettier-plugin-tailwindcss": "^0.6.14"
},
"scripts": {
"format": "prettier --write .",
"format:check": "prettier --check ."
}
}
{
"pnpm": {
"onlyBuiltDependencies": [
"@sentry/cli",
"core-js",
"esbuild",
"sharp",
"svelte-preprocess",
"workerd"
]
},
"packageManager": "pnpm@10.11.1+sha512.e519b9f7639869dc8d5c3c5dfef73b3f091094b0a006d7317353c72b124e80e1afd429732e28705ad6bfa1ee879c1fce46c128ccebd3192101f43dd67c667912",
"devDependencies": {
"concurrently": "^9.2.1",
"prettier": "^3.6.2",
"prettier-plugin-organize-imports": "^4.3.0",
"prettier-plugin-svelte": "^3.4.0",
"prettier-plugin-tailwindcss": "^0.6.14"
},
"scripts": {
"format": "prettier --write .",
"format:check": "prettier --check ."
}
}
vladdy
vladdy4w ago
and what package.json
Matthew
MatthewOP4w ago
what do you mean? have pasted the project and monorepo package.json's
vladdy
vladdy4w ago
the package.json in the node_modules folder /home/foo/projects/foo/foo/node_modules/.pnpm/@vladfrangu+async_event_emitter@2.4.7/package.json or w/e
Matthew
MatthewOP4w ago
full path is /node_modules/.pnpm/@vladfrangu+async_event_emitter@2.4.7/node_modules/@vladfrangu/async_event_emitter/package.json
vladdy
vladdy4w ago
oh and in the nested node_modules is there more than 1 thing?
Matthew
MatthewOP4w ago
ie deeper than the path you gave me
matthew@ThinkPad:~/projects/foo/catfishing/node_modules/.pnpm/@vladfrangu+async_event_emitter@2.4.7
$ tree
.
└── node_modules
└── @vladfrangu
└── async_event_emitter
├── CHANGELOG.md
├── dist
│ ├── index.cjs
│ ├── index.cjs.map
│ ├── index.d.mts
│ ├── index.d.ts
│ ├── index.global.js
│ ├── index.global.js.map
│ ├── index.mjs
│ └── index.mjs.map
├── LICENSE.md
├── package.json
├── README.md
└── THIRD_PARTY_LICENSE.md

5 directories, 13 files
matthew@ThinkPad:~/projects/foo/catfishing/node_modules/.pnpm/@vladfrangu+async_event_emitter@2.4.7
$ tree
.
└── node_modules
└── @vladfrangu
└── async_event_emitter
├── CHANGELOG.md
├── dist
│ ├── index.cjs
│ ├── index.cjs.map
│ ├── index.d.mts
│ ├── index.d.ts
│ ├── index.global.js
│ ├── index.global.js.map
│ ├── index.mjs
│ └── index.mjs.map
├── LICENSE.md
├── package.json
├── README.md
└── THIRD_PARTY_LICENSE.md

5 directories, 13 files
vladdy
vladdy4w ago
ok so the code is fine atp i feel like its wrangler doing something nasty or sentry can you check without sentry
Matthew
MatthewOP4w ago
i can look at removing sentry as you said, but it's quite a bit of editing as there's loads of sentry stuff scattered about for info my fetch and scheduled handlers are wrapped in export default Sentry.withSentry()
vladdy
vladdy4w ago
what if you import rest without await import but just import
Matthew
MatthewOP4w ago
⎔ Starting local server...
✘ [ERROR] service core:user:catfishing-tasks: Uncaught TypeError: Super expression must either be null or a function

at null.<anonymous> (index.js:130351:61) in i
at null.<anonymous> (index.js:130710:18)
at null.<anonymous> (index.js:130711:10) in 425
at null.<anonymous> (index.js:131198:20) in r
at null.<anonymous> (index.js:129019:26) in 33
at null.<anonymous> (index.js:131198:20) in r
at null.<anonymous> (index.js:131199:21)
at null.<anonymous> (index.js:131200:7)
at null.<anonymous> (index.js:128914:82)
at null.<anonymous> (index.js:128915:6) in node_modules/node-inspect-extracted/dist/inspect.js



✘ [ERROR] The Workers runtime failed to start. There is likely additional logging output above.
⎔ Starting local server...
✘ [ERROR] service core:user:catfishing-tasks: Uncaught TypeError: Super expression must either be null or a function

at null.<anonymous> (index.js:130351:61) in i
at null.<anonymous> (index.js:130710:18)
at null.<anonymous> (index.js:130711:10) in 425
at null.<anonymous> (index.js:131198:20) in r
at null.<anonymous> (index.js:129019:26) in 33
at null.<anonymous> (index.js:131198:20) in r
at null.<anonymous> (index.js:131199:21)
at null.<anonymous> (index.js:131200:7)
at null.<anonymous> (index.js:128914:82)
at null.<anonymous> (index.js:128915:6) in node_modules/node-inspect-extracted/dist/inspect.js



✘ [ERROR] The Workers runtime failed to start. There is likely additional logging output above.
whole worker fails to start
vladdy
vladdy4w ago
what the fuck is wrangler doing @Jiralite can youuu test out a wrangler setup? same ver as them? maybe its the compat date??? or the node flag?? idfk
Matthew
MatthewOP4w ago
i have a fresh repo which hits the error lemme tidy it up and publish it, will be a minute
vladdy
vladdy4w ago
this does feel like an issue to be reported to cf tho I can fix it on my end to drop the inspect and go back to how it was but yknow
vladdy
vladdy4w ago
it must be either compat date or compat flags
Matthew
MatthewOP4w ago
compat date
vladdy
vladdy4w ago
yeah infinitely appreciated that you actually helped us figure it out
Matthew
MatthewOP4w ago
haha thanks, no worries! fun saturday night
vladdy
vladdy4w ago
now the question is how do we tell cf to fix it :meguFace: annd will they even fix it
Matthew
MatthewOP4w ago
as you can tell, i know very little about pnpm and node_modules etc so sorry if it was a bit slower than it needed to be yes if i move it today's date, it goes away
vladdy
vladdy4w ago
BRUH
Matthew
MatthewOP4w ago
if you haven't got there already, 2025-05-04 is the last breaking date and 2025-05-05 is the first working date
Matthew
MatthewOP4w ago
Cloudflare Docs
Compatibility flags
Opt into a specific features of the Workers runtime for your Workers project.
vladdy
vladdy4w ago
Wtf Did you just bisect the compat dates
Matthew
MatthewOP4w ago
correct. adding the flag but keeping my original compat_date fixes it
"compatibility_date": "2024-12-30",
"compatibility_flags": [
"nodejs_compat", "enable_weak_ref"
],
"compatibility_date": "2024-12-30",
"compatibility_flags": [
"nodejs_compat", "enable_weak_ref"
],
vladdy
vladdy4w ago
Maybe inspect does things with weak refs? @Matthew hewwo, can you try @vladfrangu/async_event_emitter@2.4.9-2.0 with your current config without the weak ref flag
vladdy
vladdy4w ago
still fails, seriously??
Matthew
MatthewOP4w ago
yup. this fails: git clone -b @vladfrangu/async_event_emitter@2.4.9-2.0 git@github.com:catfishing-game/discordjs-async-issue.git && cd discordjs-async-issue && pnpm install && pnpm dev

Did you find this page helpful?