Myrkvi
Myrkvi•2mo ago

Using libraries from JSR in SvelteKit

Hi! I'm playing around with using SvelteKit with Deno 2, and tried to import a library from Deno's standard library to use that with SvelteKit. This, however, adds it into deno.json instead of package.json and I'm not able to import it in Svelte code. What would be needed to be able to import modules from JSR and make them work in SvelteKit?
5 Replies
bartlomieju
bartlomieju•2mo ago
Try using the jsr binary, eg. npx jsr add @std/fmt
Myrkvi
MyrkviOP•2mo ago
so, deno run -A npm:jsr add @std/fmt? feels a bit convoluted, but alright 😅
bartlomieju
bartlomieju•2mo ago
Yeah, it is convoluted We are aware of this problem - it's because SvelteKit uses a bundler that currently doesn't understand jsr: imports in deno.json We're trying to fix the situation to make it more approachable
Myrkvi
MyrkviOP•2mo ago
Ah okay, yeah that makes sense. Thank you for the response! :)
nathanwhit
nathanwhit•2mo ago
sveltekit uses vite for bundling, you should be able to use the deno vite plugin https://github.com/denoland/deno-vite-plugin (instructions in readme) to support deno-specific features
GitHub
GitHub - denoland/deno-vite-plugin: Vite plugin to enable Deno reso...
Vite plugin to enable Deno resolution inside vite. - denoland/deno-vite-plugin

Did you find this page helpful?