We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.1.27+267afa293
Linux 6.8.0-44-generic x86_64 x86_64
The bun --hot functionality does not seem to work correctly when dynamically importing a module which contains a top-level await.
bun --hot
const server = Bun.serve({ async fetch(req, server) { const url = new URL(req.url); if (url.pathname === "/livereload") { if (server.upgrade(req)) return; } const template = await import("./template.js"); return new Response(template.default, { headers: { "Content-Type": "text/html" }, }); }, websocket: { open(ws) { ws.subscribe("livereload"); }, close(ws) { ws.unsubscribe("livereload"); }, }, }); server.publish("livereload", "reload");
const message = await new Promise(resolve => setTimeout(resolve, 1000, "Bun LiveReload!") ); export default ` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>LiveReload</title> <script> const socket = new WebSocket("ws://localhost:3000/livereload"); socket.addEventListener("message", event => { location.reload(); }); </script> </head> <body> <h1>${message}</h1> </body> </html> `;
Steps to Reproduce:
bun --hot livereload.js
localhost:3000
"Bun LiveReload!"
template.js
The website should be reloaded according to the change.
The server throws an error:
ReferenceError: Cannot access 'default' before initialization. at /temp/livereload.js:12:25 GET - / failed 7 | } 8 | 9 | const template = await import("./template.js"); 10 | // await Bun.sleep(2000); 11 | 12 | return new Response(template.default, {
setTimeout
const message = await new Promise(resolve => setTimeout(resolve, 0, "Bun LiveReload!") ); export default ` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>LiveReload</title> <script> const socket = new WebSocket("ws://localhost:3000/livereload"); socket.addEventListener("message", event => { location.reload(); }); </script> </head> <body> <h1>${message}</h1> </body> </html> `;
Bun.sleep(2000)
const server = Bun.serve({ async fetch(req, server) { const url = new URL(req.url); if (url.pathname === "/livereload") { if (server.upgrade(req)) return; } const template = await import("./template.js"); await Bun.sleep(2000); return new Response(template.default, { headers: { "Content-Type": "text/html" }, }); }, websocket: { open(ws) { ws.subscribe("livereload"); }, close(ws) { ws.unsubscribe("livereload"); }, }, }); server.publish("livereload", "reload");
The text was updated successfully, but these errors were encountered:
No branches or pull requests
What version of Bun is running?
1.1.27+267afa293
What platform is your computer?
Linux 6.8.0-44-generic x86_64 x86_64
What steps can reproduce the bug?
The
bun --hot
functionality does not seem to work correctly when dynamically importing a module which contains a top-level await.livereload.js
template.js
Steps to Reproduce:
bun --hot livereload.js
localhost:3000
in your Browser"Bun LiveReload!"
string intemplate.js
What is the expected behavior?
The website should be reloaded according to the change.
What do you see instead?
The server throws an error:
Additional information
When setting the
setTimeout
to 0ms, the hot reload works as expected.When using
Bun.sleep(2000)
after the import, the hot reload works as expected.The text was updated successfully, but these errors were encountered: