skip to Main Content

I am developing a SvelteKit codebase in Visual Studio Code. I am using Svelte plugin for Visual Studio Code.

For load(), POST(), GET(), et. Visual Studio Code linter complains:

Cannot find module './$types.js' or its corresponding type declarations. (this likely means that SvelteKit's type generation didn't run yet - try running it by executing 'npm run dev' or 'npm run build')ts(2307)

enter image description here

enter image description here

  • This is an old codebase
  • I am running npm run dev and also have run npm run build
  • I also run the quick before to install "@types/node": "^20.12.7" – no more quick fixes available

What could be wrong with the configuration, and how to configure Visual Studio Code to correctly resolve function signatures for SvelteKit?

2

Answers


  1. Try removing the extension .js from ./$types.js.

    Login or Signup to reply.
  2. I can see a similar error message reported in sveltejs/language-tools, packages/typescript-plugin/src/language-service/diagnostics.ts

    // If not "Cannot find module './$types' .." then filter out
    

    That comes from PR 1918 which mentions:

    This allows you to omit the ./$types imports and still get proper typings, by inserting them under the hood. Example:

    // +page.ts
    export function load(event) {}
    --->
    export function load(event: import('./$types').PageLoadEvent) {}
    

    This works for TS files, in Svelte files, and for svelte-check.

    Works in special SvelteKit files (+page/layout(.server).ts/js) for all exports (actions/csr/ssr/prerender/trailingSlash/load)

    So check your own (old) code, and try to manually import the missing ./$types.js in your case, similar to what the PR example was illustrating.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search