oven-sh / bun

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

Error 500 on any SvelteKit app when accessing static assets (and possibly more) #6786

Open jerefrer opened 10 months ago

jerefrer commented 10 months ago

What version of Bun is running?

1.0.7+b0393fba6200d8573f3433fb0af258a0e33ac157

What platform is your computer?

Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

  1. Run:
bun create svelte@latest example-app
bun install
bun run dev
  1. Open http://localhost:5173/favicon.png

What is the expected behavior?

To see the favicon.

What do you see instead?

TypeError: parse is not a function
    at /home/lekshe/js/example-app/node_modules/sirv/build.js:168:18
    at file:///home/lekshe/js/example-app/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:390:7
    at call (file:///home/lekshe/js/example-app/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:50689:7)
    at next (file:///home/lekshe/js/example-app/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:50633:5)
    at Function.handle (file:///home/lekshe/js/example-app/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:50636:3)
    at Server.app (file:///home/lekshe/js/example-app/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:50501:37)
    at Server.emit (node:events:514:28)
    at parserOnIncoming (node:_http_server:1107:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)

Additional information

An issue has been open over to SvelteKit where they explained that the issue must come from bun:

The issue occurs because bun is resolving the dependencies incorrectly. It downloads the wrong version of @polka/url so the parse function is not exported, but is needed by SvelteKit.

If you look inside node_modules, and take a look at the package.json of the sirv package, you'll see that @polka/url specifies version 1.0.0-next.20:

  "dependencies": {
    "@polka/url": "^1.0.0-next.20",
    "mrmime": "^1.0.0",
    "totalist": "^3.0.0"
  }

However, bun is installing version 1.0.0-next.9 (take a look at the @polka/url folder in node_modules next). This is not the case with other package managers such as pnpm.

I think this is a bun issue so I'll go ahead and close this for now.

RobinPourtaud commented 10 months ago

Same problem with Bun and Nuxt!

bitdom8 commented 10 months ago

Same with bun and sveltekit @jerefrer

Foorack commented 10 months ago

Able to reproduce with latest SvelteKit (1.27.2) and Bun (1.0.7). :ok:

aleksasiriski commented 10 months ago

Was just converting my SvelteKit app from node adapter to bun and encountered this issue as well. If using assets folder and importing images in script tags and using that var in HTML is works, but I need some static files that are served without pages.

Wertik commented 9 months ago

As long as this is not resolved.

I managed to work around this issue using the bun overrides section.

  "overrides": {
    "@polka/url": "1.0.0-next.20"
  }
notramo commented 9 months ago

This seems to be fixed since. I could not reproduce it with the provided instructions.