import.meta.hot is undefined when using hono with bun.
I am trying to add a function to the dispose callback as documented here:
https://bun.sh/docs/bundler/hmr?utm_source=chatgpt.com#import-meta-hot-api-reference
but when I log
import.meta
there isn't even a hot
property in there.
I am using "hono": "^4.7.10"
and bun 1.2.13
.
This is the script I am using to start the dev server :
"dev": "bun run --hot src/index.ts"
Bun
Hot reloading – Bundler | Bun Docs
Update modules in a running application without reloading the page using import.meta.hot
14 Replies
Source code or it didn’t happen
Also I’d recommend ditching chatgpt
nothing to do with hono, you're basically doing what the reference you linked is telling you not to do, for example you must use
import.meta.hot.dispose(() => {...})
inline
This is the code I am trying to use to unsubscribe from a websocket connection:
the the console.log() does never get executed even if I don't do the
if (import.meta.hot)
check. Thats why I console logged the meta object to see if "hot" even exists: console.log(import.meta)
but it doesn't contain the hot
propertyhm. i assume you're running this localy?
Correct
strange. it shouldn't be getting shaken out then
i haven't worked w this api before though, so idk
have you tried without the
unsubscribe
? i.e., just the logIt also doesnt work without the unsubscribe. Does it matter where I place this listener? If its at the end of the file or not?
rip
no idea. i wouldn't expect it to though
Ok guess I manually restart the dev server then
what happens if you just hot reload w/o unsubscribing?
The callback of my websocket gets called multiple times and the connections add every time I hot reload without unsubscribing
ah, i see
if you share a minimal repro, i can mess around w it later today
i can repro, but still have no idea what the issue is
i did notice that "HMR is enabled by default when using Bun's full-stack development server.", which is not how you have your project set up
but setting up the full-stack server didn't help
i'm wondering whether
import.meta.hot
is only available for client-side modules