Menu

1 / 2

Fix "Cannot find module" TypeScript Errors Without Touching a Single Line of Code

DEV Community·Shawon Saha·7 months ago
#DhVBguU0
#vscode#typescript#webdev#file#server
Reading 0:00
15s threshold

You've just created a new file. TypeScript swears it doesn't exist. Here's why — and the one-second fix.

The problem

You add a new file to your project. You import from it. A red squiggly appears instantly:

Cannot find module './filename' or its corresponding type declarations

Enter fullscreen mode

Exit fullscreen mode

But the file is right there. You can see it in the file tree. You've already run tsc --noEmit and zero errors came back. So what's going on?

The culprit: a stale language server

VS Code (and most TypeScript-aware editors) run a background TypeScript language server process that powers autocomplete, type-checking, and error highlighting. This server caches a snapshot of your project's file graph.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.