oven-sh / bun

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

SvelteKit not working with `workspaces` #4174

Closed kansson closed 9 months ago

kansson commented 10 months ago

What version of Bun is running?

0.7.4

What platform is your computer?

Darwin 22.6.0 arm64 arm

What steps can reproduce the bug?

Create Bun project with workspaces and a SvelteKit app. Run the Vite dev server inside Bun using the latest version of all packages.

What is the expected behavior?

The dev server should start without any error.

What do you see instead?

[vite] Internal server error: Failed to resolve import "../../../../node_modules/@sveltejs/kit/src/runtime/components/error.svelte" from ".svelte-kit/generated/client/nodes/1.js". Does the file exist?
  Plugin: vite:import-analysis
  File: /Users/isak/code/project/packages/app/.svelte-kit/generated/client/nodes/1.js:1:39
  1  |  export { default as component } from "../../../../node_modules/@sveltejs/kit/src/runtime/components/error.svelte";
     |                                        ^
      at formatError (/Users/isak/project/project/node_modules/vite/dist/node/chunks/dep-df561101.js:43993:16)
      at error (/Users/isak/code/project/node_modules/vite/dist/node/chunks/dep-df561101.js:43988:47)

Additional information

The problem is that SvelteKit can't find the component as it's hoisted to the root node_modules in the project. Maybe this should work if Vite used Buns bundler and module resolution?

huseeiin commented 10 months ago

i'm having the same problem but with node

remorses commented 10 months ago

This is probably caused by #4274

hasanyasin commented 10 months ago

The issue us not about bunjs, but about locating the node_modules folder which might be in a parent folder when using workspaces.

I believe the code block shared above was generated with the assumption of having the node_modules folder at the Svelte project's source root, which does not comply with the resolution strategy of Node.js either. All the runtimes that I tried before would search packages in node_modules folders under all the parent folders by traversing up until the package is found.

The code generation should not assume having the node_modules in the Svelte project root.

Until fixed, a remedy is to create a symlink to the actual node_modules folder inside the SvelteKit project root:

/my/workspace/svelte/project/ $ ln -s ../../node_modules ./

edit: I was just browsing on the tablet and didn't realize this was under bunjs repo. This specific problem is in Svelte Kit (or maybe vitejs), not bun, unless the bogus path (../../....) was gathered from bun api by the mentioned modules.

kansson commented 9 months ago

This appears to be functioning correctly now with Bun v1.0.3. If anyone encounters this error, please leave a reply, and I will reopen the issue.