oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.23k stars 2.77k forks source link

Hot reload not working on WSL #5155

Open Lekato98 opened 1 year ago

Lekato98 commented 1 year ago

What version of Bun is running?

1.0.1+31aec4ebe325982fc0ef27498984b0ad9969162b

What platform is your computer?

WSL Ubuntu 20.04 Over Microsoft Windows NT 10.0.22621.0 x64

What steps can reproduce the bug?

  1. install express & types bun install express bun install -d @type/express
  2. Copy the below snippet code to index.ts
    
    import express from 'express';
    const app = express();

app.get('*', (req, res) => res.json({healthCheck: 'OKZ'}))

app.listen(8080, () => console.info('Server listening to 8080'))


3. run the app using `hot` or `watch`  [`bun --watch index.ts` or `bun --hot index.ts`]
4. Hit localhost:8080 and you should receive **OKZ** as a response
5. While the server is running, replace `OKZ` with `OKAYZ`
6. Hit the endpoint back and you will receive **OKZ** again

### What is the expected behavior?

While the server is running using `--watch` or `--hot` it should perform hot reload for the application, so instead of receiving **OKZ** in step #6 instead it should return **OKAYZ**

### What do you see instead?

While the server is running using `--watch` or `--hot` I keep receiving the initial server build

### Additional information

There is an open thread on discord, [link](https://discord.com/channels/876711213126520882/1149820425761738884)
a4amado commented 1 year ago

Same error here, I faced the same error with WSL, I installed Ubuntu and still face the same error.

angelhdzdev commented 1 year ago

Same issue here since yesterday. I thought I was doing something wrong. Ubuntu WSL. Also having other issues with Hono and Elysia and the request body... SyntaxError: Unexpected end of JSON input... also reported.

Edit: Solved this in a later reply. Also solved the Elysia/Hono issue, I was using a GET request of course the body is not valid!

riley-git commented 1 year ago

If your project is located in the windows file system and you're accessing them through /mnt with WSL, hot reload will not work. See here.

Moving my project and working within Linux environment allowed me to use --hot.

angelhdzdev commented 1 year ago

If your project is located in the windows file system and you're accessing them through /mnt with WSL, hot reload will not work. See here.

Moving my project and working within Linux environment allowed me to use --hot.

Thank you! Solved for me.

Anyone knows how to open a VSCode window on Windows but using the linux file system with WSL? I managed to move my bun project from windows file system to linux file system and now --watch/--hot work, but I lose all my VSCode extensions because it's using a linux version of VSCode...

Edit: Nevermind. All extensions are installed. What I lost was the shortcuts to them on the left sidebar.

Edit 2: To anyone that needs this tip, to open VSCode in the linux file system with WSL: Install these extensions: image

And then: image

https://github.com/oven-sh/bun/assets/10191085/37afc93f-5607-4381-add2-5b268b8cc586

Edit 3: Got my extensions working. I had to browse the extensions I use, and then I get a hint besides the extensions name "install in WSL". Some extensions need this.

angelhdzdev commented 1 year ago

Thanks, feel free to close the ticket since I've shared my feedback and there is no further action required. Regards, Hamza On Thu, Sep 14, 2023 at 11:21 PM Angel Hernandez @.> wrote: If your project is located in the windows file system and you're accessing them through /mnt with WSL, hot reload will not work. See here <#4335 (comment)>. Moving my project and working within Linux environment allowed me to use --hot. Thank you! Solved for me. Anyone knows how to open a VSCode window on Windows but using the linux file system with WSL? I managed to move my bun project from windows file system to linux file system and now --watch/--hot work, but I lose all my VSCode extensions because it's using a linux version of VSCode... — Reply to this email directly, view it on GitHub <#5155 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKE3OQFBA4ZJ5Q5ZGGNVRMDX2NRLDANCNFSM6AAAAAA4VNI5IM . You are receiving this because you authored the thread.Message ID: @.>

I'm not the Issue's author. Thank you.

Lekato98 commented 1 year ago

Hey Angel,

I sent the email in the wrong window, it was for a different topic, lol.

Please ignore it!

Thanks

On Sat, Sep 16, 2023 at 11:42 PM Angel Hernandez @.***> wrote:

Thanks, feel free to close the ticket since I've shared my feedback and there is no further action required. Regards, Hamza … <#m-6604571682452136913> On Thu, Sep 14, 2023 at 11:21 PM Angel Hernandez @.> wrote: If your project is located in the windows file system and you're accessing them through /mnt with WSL, hot reload will not work. See here <#4335 (comment) https://github.com/oven-sh/bun/issues/4335#issuecomment-1694387577>. Moving my project and working within Linux environment allowed me to use --hot. Thank you! Solved for me. Anyone knows how to open a VSCode window on Windows but using the linux file system with WSL? I managed to move my bun project from windows file system to linux file system and now --watch/--hot work, but I lose all my VSCode extensions because it's using a linux version of VSCode... — Reply to this email directly, view it on GitHub <#5155 (comment) https://github.com/oven-sh/bun/issues/5155#issuecomment-1720090032>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKE3OQFBA4ZJ5Q5ZGGNVRMDX2NRLDANCNFSM6AAAAAA4VNI5IM https://github.com/notifications/unsubscribe-auth/AKE3OQFBA4ZJ5Q5ZGGNVRMDX2NRLDANCNFSM6AAAAAA4VNI5IM . You are receiving this because you authored the thread.Message ID: @.>

I'm not the Issue's author. Thank you.

— Reply to this email directly, view it on GitHub https://github.com/oven-sh/bun/issues/5155#issuecomment-1722312240, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKE3OQHQJUSK24L2SQ7PY2TX2YFL7ANCNFSM6AAAAAA4VNI5IM . You are receiving this because you authored the thread.Message ID: @.***>

angelhdzdev commented 1 year ago

@Yordan Trivada Bian didn't find your reply in the bun hot reload Issue page. I just learned we can reply via email!

Anyway, as far as I know, and I can be wrong of course, the hot reloading on the browser needs communication via sockets, and that's how Vite does it. The browser needs to connect to the server and know when the code changed and was rebuilt to add the modified changes to the DOM.

It happened to me with a library that is Vite Node, I was so used to Vite's hot reload in the browser, that when I tried a backend project, I expected the browser to also reload hahaha. 😂

Maybe Bun's hot reload injects some code in the served HTML pages to achieve this, I will read about it now.


From: Yordan Trivada Bian @.> Sent: Monday, September 18, 2023 2:17 PM To: oven-sh/bun @.> Cc: Angel Hernandez @.>; Comment @.> Subject: Re: [oven-sh/bun] Hot reload not working on WSL (Issue #5155)

If your project is located in the windows file system and you're accessing them through /mnt with WSL, hot reload will not work. See herehttps://github.com/oven-sh/bun/issues/4335#issuecomment-1694387577.

Moving my project and working within Linux environment allowed me to use --hot.

thanks this solve the issue. Now I could see my file reload in the terminal, but when I setup an http server my browser (chrome) didn't reload automaticaly (I have to refresh to see the changes). Do you have any clue to solve this?

— Reply to this email directly, view it on GitHubhttps://github.com/oven-sh/bun/issues/5155#issuecomment-1724138805, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACNYB3MLVLJ3TEKMYRJEAZLX3CF3FANCNFSM6AAAAAA4VNI5IM. You are receiving this because you commented.Message ID: @.***>

angelhdzdev commented 1 year ago

Oh look! From bun's docs: [cid:703ec706-b9e1-40ee-a38c-3d31ebf98cac] image


From: Angel Hernandez @.> Sent: Tuesday, September 19, 2023 3:41 PM To: oven-sh/bun @.> Subject: Re: [oven-sh/bun] Hot reload not working on WSL (Issue #5155)

@Yordan Trivada Bian didn't find your reply in the bun hot reload Issue page. I just learned we can reply via email!

Anyway, as far as I know, and I can be wrong of course, the hot reloading on the browser needs communication via sockets, and that's how Vite does it. The browser needs to connect to the server and know when the code changed and was rebuilt to add the modified changes to the DOM.

It happened to me with a library that is Vite Node, I was so used to Vite's hot reload in the browser, that when I tried a backend project, I expected the browser to also reload hahaha. 😂

Maybe Bun's hot reload injects some code in the served HTML pages to achieve this, I will read about it now.


From: Yordan Trivada Bian @.> Sent: Monday, September 18, 2023 2:17 PM To: oven-sh/bun @.> Cc: Angel Hernandez @.>; Comment @.> Subject: Re: [oven-sh/bun] Hot reload not working on WSL (Issue #5155)

If your project is located in the windows file system and you're accessing them through /mnt with WSL, hot reload will not work. See herehttps://github.com/oven-sh/bun/issues/4335#issuecomment-1694387577.

Moving my project and working within Linux environment allowed me to use --hot.

thanks this solve the issue. Now I could see my file reload in the terminal, but when I setup an http server my browser (chrome) didn't reload automaticaly (I have to refresh to see the changes). Do you have any clue to solve this?

— Reply to this email directly, view it on GitHubhttps://github.com/oven-sh/bun/issues/5155#issuecomment-1724138805, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACNYB3MLVLJ3TEKMYRJEAZLX3CF3FANCNFSM6AAAAAA4VNI5IM. You are receiving this because you commented.Message ID: @.***>

Yor-dan commented 1 year ago

@Yordan Trivada Bian didn't find your reply in the bun hot reload Issue page. I just learned we can reply via email!

Anyway, as far as I know, and I can be wrong of course, the hot reloading on the browser needs communication via sockets, and that's how Vite does it. The browser needs to connect to the server and know when the code changed and was rebuilt to add the modified changes to the DOM.

It happened to me with a library that is Vite Node, I was so used to Vite's hot reload in the browser, that when I tried a backend project, I expected the browser to also reload hahaha. 😂

Maybe Bun's hot reload injects some code in the served HTML pages to achieve this, I will read about it now.


From: Yordan Trivada Bian @.> Sent: Monday, September 18, 2023 2:17 PM To: oven-sh/bun @.> Cc: Angel Hernandez @.>; Comment @.> Subject: Re: [oven-sh/bun] Hot reload not working on WSL (Issue #5155)

If your project is located in the windows file system and you're accessing them through /mnt with WSL, hot reload will not work. See herehttps://github.com/oven-sh/bun/issues/4335#issuecomment-1694387577.

Moving my project and working within Linux environment allowed me to use --hot.

thanks this solve the issue. Now I could see my file reload in the terminal, but when I setup an http server my browser (chrome) didn't reload automaticaly (I have to refresh to see the changes). Do you have any clue to solve this?

— Reply to this email directly, view it on GitHubhttps://github.com/oven-sh/bun/issues/5155#issuecomment-1724138805, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACNYB3MLVLJ3TEKMYRJEAZLX3CF3FANCNFSM6AAAAAA4VNI5IM. You are receiving this because you commented.Message ID: @.***>

thank you for your reply, I was confused by the docs where they show the browser reload side by side comparison with nodemon in Watch Mode > --hot mode section.

exactly like what you did mention, I am currently learning svelte which also has hot reload, and I am just so used to it that I even expect backed code to reflect hot reload in the browser without send a new request 😂

jakeg commented 11 months ago

Can confirm both --hot and --watch don't work in WSL on files from Windows' file system. It never reloads. It would be good if Bun at least showed a message to say it doesn't work.

AJR07 commented 5 months ago

Just want to resurface this issue of not being able to --hot and --watch on WSL, would be great if a fix or a notice can be implemented.