-
Notifications
You must be signed in to change notification settings - Fork 45
Using with Sveltekit #35
Comments
Thanks! I’m not too familiar with Svelte but I am guessing this is pnpm problem. Can you try installing it with Npm or Yarn to see if it works? The way it works is that it still needs React in there but React won’t end up in your bundle if you only use Lamina/vanilla |
R3F should be optional here alongside react. |
Right, I will fix that thanks! |
Ran into the same issue using lamina with SvelteKit! My workaround was to turn off ssr (I did it for my whole project, but pretty sure you could just disable it for the routes that use lamina): Create a import type { Handle } from '@sveltejs/kit';
export const handle: Handle = async ({ event, resolve }) => {
return await resolve(event, { ssr: false });
}; I don't understand exactly how this all works, but it got me through the build. For reference: https://github.com/AlexWarnes/lamina-spatula/blob/main/src/hooks.ts |
Yikes, prob best to let Sveltekit know of that issue with package resolution with SSR -- that can load multiple versions of libraries and cause deeper breakage. Another issue with their bundler's interop of non-default exports, but |
@nilskj I have updated the deps like Cody mentioned. Let me know if the error is gone or is different |
Thank you all for quick help. I see @AlexWarnes (awesome project btw), disabling SSR makes it build, but I don't want to disable SSR since my project is a website and this particular page with the 3D stuff needs some server rendering. When upgrading lamina I see the package deps have updated:
I made a new svelte-kit app and used normal npm instead of pnpm and then I don't get these errors so I don't know if they are about pnpm. If I tried changing to your workaround @CodyJasonBennett, like this:
All here above reproduced in an empty sveltekit app. |
I think these are clearly pnpm and svelte issues, if you could forward these to their respective repositories. |
That error message is coming from Node.js. It looks to me like the problem is that this library is using file extensions that are not valid with Node. The ESM version needs to end with |
That is also an issue with three (they go halfway with three.cjs and three.module.js), but I don't think it's reasonable to expect everyone to follow Node's conventions for ESM in web-only libraries. In any case, there are still issues evident with interop since CJS on the server-side should merely be an implementation detail to users that are otherwise writing with ES6 syntax. |
You only ever need to go halfway. If you have This really isn't anything Svelte or pnpm can change as neither are responsible for this. The page is being rendered during SSR and so the libraries get loaded. The user could load the libraries only on the client, but it's harder / uglier to set that up and it'd be much nicer if it just used file endings that work. It's all hidden to the user, so there's no real downside to changing the extensions |
I see, you mean in regards to Node resolution -- three has resolved this already (via type="module" and .cjs), and we still need to do the same here in Lamina. If I'm understanding you correctly, we'd need Lines 2 to 8 in 7c6ad54
|
You don't necessarily have to add |
Wanted to expand on the previous solution for future reference as some things have changed with SvelteKit and, like you mentioned @nilskj, disabling SSR is not at all ideal! (and I've had this issue with other dependencies as well) Option 1 const config = {
ssr: {
noExternal: [
'three',
'lamina',
'three-custom-shader-material',
]
},
plugins: [sveltekit()],
}; Option 2 Disclaimer
|
Hm, I'm having issues using lamina in a sveltekit project. I see the missing dependencies message, and my imports from lamina/vanilla all resolve to undefined at runtime (in my editor typescript is happy). If I make the suggested changed to |
Fantastic lib! I'm using it in my svelte-kit app (with pnpm).
First I get these worrying error messages, is there a way to only import the vanilla parts of this?
It does however run and work very nice in dev, but when building for production I face this error:
I see the package both provides a .cjs and a .js esm export, and I do try importing the esm one like this:
Any idea on how I should configure vite to be able to build this?
The text was updated successfully, but these errors were encountered: