Menu

Post image 1
Post image 2
1 / 2
0

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

DEV Community·Shawon Saha·about 1 month ago
#DhVBguU0
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. When you create a brand-new file, the server sometimes doesn't notice — so it flags imports from that file as missing, even though the compiler itself is perfectly happy. This is a known rough edge of the TS language server, not a problem with your code or your configuration.…

Continue reading — create a free account

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

Read More