Skip to content
New issue

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

SvelteKit not working with workspaces #4174

Closed
kansson opened this issue Aug 16, 2023 · 4 comments
Closed

SvelteKit not working with workspaces #4174

kansson opened this issue Aug 16, 2023 · 4 comments
Labels
bug Something isn't working bun install Something that relates to the npm-compatible client

Comments

@kansson
Copy link

kansson commented Aug 16, 2023

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?

@kansson kansson added the bug Something isn't working label Aug 16, 2023
@huseeiin
Copy link
Contributor

i'm having the same problem but with node

@remorses
Copy link

remorses commented Sep 4, 2023

This is probably caused by #4274

@hasanyasin
Copy link

hasanyasin commented Sep 7, 2023

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.

@robobun robobun added the bun install Something that relates to the npm-compatible client label Sep 9, 2023
@kansson
Copy link
Author

kansson commented Sep 24, 2023

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.

@kansson kansson closed this as completed Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun install Something that relates to the npm-compatible client
Projects
None yet
Development

No branches or pull requests

5 participants