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
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.
Quick test: if
tscon the command line shows no errors but your editor shows red squiggles on a new import, this is almost certainly the cause.
The fix: restart the TS server in VS Code
- Open the command palette with
Cmd + Shift + P(macOS) orCtrl + Shift + P(Windows/Linux). - Type
TypeScript: Restart TS Serverand press Enter. - Wait a few seconds. The language server re-indexes your project, discovers the new file, and the error disappears.
No configuration changes. No file edits. No restarting the entire editor. Just a server restart and you're back to work.
Why does this happen?
TypeScript's compiler (tsc) reads from the filesystem at the moment you run it, so it always sees the correct state. The language server is different — it's a long-running process that watches for file changes via filesystem events. Those events are not perfectly reliable, particularly on macOS (which uses FSEvents) when files are created programmatically or by tooling rather than directly in the editor. The server misses the creation event and its cached file graph goes stale.
Restarting the server forces a full re-scan, which resolves the inconsistency immediately.
Other editors
The same issue can occur in JetBrains IDEs (WebStorm, IntelliJ) and Neovim with LSP plugins. The fix is the same concept: restart or invalidate the TypeScript language server.
-
JetBrains:
File → Invalidate Caches → Restart -
Neovim:
:LspRestart
If the error persists after restarting the server, double-check that the file path and export names in your import statement exactly match those in the new file — casing matters on Linux systems.