H
Hono5mo ago
Wizzel

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
ambergristle
ambergristle5mo ago
Source code or it didn’t happen Also I’d recommend ditching chatgpt
Maston
Maston5mo ago
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
No description
Wizzel
WizzelOP5mo ago
This is the code I am trying to use to unsubscribe from a websocket connection:
if (import.meta.hot) {
import.meta.hot.dispose(() => {
console.log("Cleaning up before hot reload..");
unsubscribe();
});
}
if (import.meta.hot) {
import.meta.hot.dispose(() => {
console.log("Cleaning up before hot reload..");
unsubscribe();
});
}
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 property
ambergristle
ambergristle5mo ago
hm. i assume you're running this localy?
Wizzel
WizzelOP5mo ago
Correct
ambergristle
ambergristle5mo ago
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 log
Wizzel
WizzelOP5mo ago
It also doesnt work without the unsubscribe. Does it matter where I place this listener? If its at the end of the file or not?
ambergristle
ambergristle5mo ago
rip no idea. i wouldn't expect it to though
Wizzel
WizzelOP5mo ago
Ok guess I manually restart the dev server then
ambergristle
ambergristle5mo ago
what happens if you just hot reload w/o unsubscribing?
Wizzel
WizzelOP5mo ago
The callback of my websocket gets called multiple times and the connections add every time I hot reload without unsubscribing
ambergristle
ambergristle5mo ago
ah, i see if you share a minimal repro, i can mess around w it later today
ambergristle
ambergristle5mo ago
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

Did you find this page helpful?