How to clean typescript cache?

Viewed 21800

I don't know where to look at, and typescript answer here said that it is not cached

But it clearly cached the files. because this is my import

import definition

And yet, it cannot import the file from old path.

Cannot find module

I have searched for all definition.ts file, and all has been updated

Definition search

I am lost here..

4 Answers

If you are using VSCode, you can use CTRL + SHIFT + P to open the command palette and search for "Reload", you should have "Reload TS Server" and "Reload Project", both work well.

@tl;dr Usually when this sort of thing happens to me, deleting the build/lib/dist directory or whatever you call it, solves the issues.

This usually happens to me when I have something like:

file.ts

and,having previously built something, rename it to a directory such as:

file/index.ts

Since renaming files wont delete them in the ./lib directory(or whatever you call it in your project), unless you delete said directory and re-build, you will have entries:

file.ts
file/index.ts

Which (at least for me) often leads to such type of errors.

I had this issue where typescript was "caching" old references and the problem was that I had an old "@types/cheerio" dev dependency installed.

My problem was:

I had "cheerio 0.22" and "@types/cheerio 0.22". I've updated cheerio to 1.0-rc6, but did not update the @types/cheerio. So typescript was complaining that method "load" had only 2 arguments and not 3.

So, despite of cheerio 1.0-rc6 had an index.d.ts file correctly with 3 arguments, my old "@types/cheerio" installation had only 2 arguments, so the typescript lint was "stuck" with the wrong information (restating vscode did not solve, only uninstalling the @types dependency).

Ok.. I am not sure how it was fixed, but I reformatted my Z drive to fix it. Thankfully, I isolated my working code from the rest of the drive. It seems the only way is to clean your working folder

Note: befor that

npm cache clean [<path>]
Related