SvelteKit: Unable to load a local module for './$types'
The
./$types
module resolves just fine in my .svelte
files but not in .ts
-routes. Any idea how to fix this?5 Replies
I can still
import type { LayoutLoad } from '../../.svelte-kit/types/src/routes/$types.d.ts';
but that's not how it's supposed to beI wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided, it seems like you might be encountering a module resolution issue specific to SvelteKit when working with TypeScript files.
In SvelteKit, the
./$types
path is typically used for loading types that are specific to SvelteKit's file-based routing. If this path is resolving fine in .svelte
files but not in .ts
route files, it could be an issue with how TypeScript is configured to resolve these types of paths.
One thing to check is your tsconfig.json
file. Make sure that it is configured to include the types from SvelteKit. You might need to adjust the paths
or baseUrl
settings to ensure that TypeScript can resolve the ./$types
module correctly.
Here's an example of what you might include in your tsconfig.json
:
Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice and consult the SvelteKit documentation or community for more specific guidance on this issue.The problem is that Deno at the moment doesn't support the
rootDirs
option
that SvelteKit uses to resolve these generated files. See this issue:
https://github.com/denoland/deno/issues/26871
My workaround for now is to not enable VSCode/Deno in the SvelteKit project
itself and embed the Deno TypeScript definitions directly in the project:
Not sure if there are better ways to work around the current limitation.GitHub
rootDirs and SvelteKit · Issue #26871 · denoland/deno
deno 2.0.6 (stable, release, aarch64-apple-darwin) v8 12.9.202.13-rusty typescript 5.6.2 Hi, I am using SvelteKit and I am trying to reproduce this example: import type { PageLoad } from './$ty...
Indeed 1) not enabling Deno extension in the svelte directory and 2) installing Deno types is a workaround. See for example: https://discord.com/channels/684898665143206084/1288450364760264827/1288956395533635679
deno add --dev npm:@types/deno
@bondsandbarrels ah nice! ❤️
didn't know about that 😃