hmt
hmt2mo ago

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?
2 Replies
hmt
hmt2mo ago
I can still import type { LayoutLoad } from '../../.svelte-kit/types/src/routes/$types.d.ts'; but that's not how it's supposed to be
Deno AI Helper
Deno AI Helper2mo ago
I 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:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"$types/*": ["./path-to-your-types-folder/*"]
}
}
}
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"$types/*": ["./path-to-your-types-folder/*"]
}
}
}
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.