oven-sh / bun

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

Error with Sveltekit production builds #7951

Open paulGeoghegan opened 10 months ago

paulGeoghegan commented 10 months ago

What version of Bun is running?

1.0.21+837cbd60d

What platform is your computer?

Oficial docker image

What steps can reproduce the bug?

I have been experiencing a bug where after I run:

bun run build
then
bun ./build/index.js

The server will start on 0.0.0.0:3000 but when I go to localhost:3000 I get the following error:

> Using svelte-adapter-bun
  ✔ Start server with: bun ./build/index.js
  ✔ done
✓ built in 11.73s
vscode ➜ /workspaces/Envisionly-Website (main) $ bun ./build/index.js
Listening on 0.0.0.0:3000
709 |     }
710 |   });
711 | };
712 | var get_origin = function(headers) {
713 |   const protocol = protocol_header && headers.get(protocol_header) || "https";
714 |   const host = headers.get(host_header);
                     ^
TypeError: Invalid header name: ''
      at get_origin (/workspaces/Envisionly-Website/build/index.js:714:16)
      at ssr (/workspaces/Envisionly-Website/build/index.js:682:24)

709 |     }
710 |   });
711 | };
712 | var get_origin = function(headers) {
713 |   const protocol = protocol_header && headers.get(protocol_header) || "https";
714 |   const host = headers.get(host_header);
                     ^
TypeError: Invalid header name: ''
      at get_origin (/workspaces/Envisionly-Website/build/index.js:714:16)
      at ssr (/workspaces/Envisionly-Website/build/index.js:682:24)

^[[21;2~^[[21;2~^[[21;2~^[[B^[[B^[[21;2~^[[B^[[B

I tried the same thing using the node adapter and did not face the same problem so it seems like this is an issue with BUN or it's adapter. This also worked perfectly fine up I think version 1.0.20.

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

JohannesKlauss commented 10 months ago

As a workaround you can set the ORIGIN, PROTOCOL_HEADER and HOST_HEADER environment variables:

#.env
ORIGIN=http://localhost:3000
PROTOCOL_HEADER=x-forwarded-proto
HOST_HEADER=x-forwarded-host
paulGeoghegan commented 10 months ago

I'll try this out but do you know why this is happening?

JohannesKlauss commented 10 months ago

No, sorry, I hadn't time to dig around.

paulGeoghegan commented 10 months ago

Okay so I tried it out but it didn't work. I currently have the following in my .env file:

ORIGIN=http://localhost:8080
PROTOCOL_HEADER=x-forwarded-proto
HOST_HEADER=x-forwarded-host

I'm still getting the same error and despite using port 8080 in the .env file it still says the following after running bun run start in the build directory:

$ bun ./index.js
Listening on 0.0.0.0:3000
JohannesKlauss commented 10 months ago

These two things are unrelated. The ORIGIN env just tells sveltekit what the base domain of your app is. It does not configure your port.

paulGeoghegan commented 10 months ago

This did indeed fix the problem once I changed it to localhost:3000 in my .env file. Thanks so much! This definitely should be fixed properly but I'm glad there was a workaround.