I have some problems running --watch
in bun, it's not updating my page in real-time, and I always have to rerun it to see the changes.
I think it's because I'm using Linux on Windows, but I don't know if it's just a bug with me, because I didn't find it anywhere. Any clues?
My code example:
import { serve } from "bun";
console.log("I restarted at:", Date.now());
serve({
port: 4003,
fetch(request) {
return new Response("Susdsdp");
},
});
Inside the Terminal, I restarted at: 1695345688409
And only send me this message once.
I've already used --hot
and --watch
At There might be Limitations or compatibility issues using Filesystem Watcher using WSL on the version of Bun that you're using. So Id check that first.
Try running form a typescript file on the server
Bun.version; // => "0.6.15"
Bun.revision; // => "49231b2cb9aa48497ab966fc0bb6b742dacc4994"
Update bun if needed npm install bun@latest
.
Check that you're file paths and names don't contain special characters that might interfere with Bun's file watching capabilities. Also keep in mind that Linux file system events do not always propagate correctly when using WSL. This can affect tools that rely on filesystem watchers, like Bun. So you may want to try increasing the inotify watch limit in WSL with:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Then, Ensure that Bun has the necessary permissions to watch files and directories also ensure your project directory is within the WSL file system i.e., /home/username/project
and not under the mounted Windows file system i.e., /mnt/c/Users/username/project
.
If you're working in a large codebase, Bun might be trying to watch too many files. Try restricting the watch to specific directories or files.
If none of the above solutions work, you could consider opening an issue on Bun's GitHub repository. It might be a bug that the maintainers aren't aware of, especially if it's specific to WSL environments. In your case, given that you've used both --hot
and --watch
, it's likely that the issue lies with WSL's filesystem watcher limitations.
Try the solutions mentioned above, especially the one related to increasing the inotify watch limit, as that's a common solution for similar issues with other tools in a WSL environment.