TypeScript: Tsconfig show typescript file not found error after moving it to another directory or delete it.
Issue Type: Bug
When I move a typescript file from a directory into another directory or delete the file from vscode, it shows a problem in tsconfig.json
file:
File '/home/justin/Projects/dochub/src/menu.ts' not found.
The file is in the program because:
Matched by include pattern '**/* ' in '/home/justin/Projects/dochub/tsconfig.json' ts [1, 1]
I mean, yeah of course it’s not found because I moved it into another directory.
Reopening vscode will solve this, but it is annoying … Hope this will be fixed soon 😃
VS Code version: Code 1.55.2 (3c4e3df9e89829dce27b7b5c24508306b151f30d, 2021-04-13T09:37:02.931Z) OS version: Linux x64 5.11.0-16-generic snap
System Info
Item | Value |
---|---|
CPUs | AMD Ryzen 3 2200U with Radeon Vega Mobile Gfx (4 x 545) |
GPU Status | 2d_canvas: unavailable_software gpu_compositing: disabled_software multiple_raster_threads: enabled_on oop_rasterization: disabled_off opengl: disabled_off protected_video_decode: disabled_off rasterization: disabled_software skia_renderer: enabled_on video_decode: disabled_software vulkan: disabled_off webgl: unavailable_software webgl2: unavailable_software |
Load (avg) | 3, 3, 3 |
Memory (System) | 14.66GB (0.16GB free) |
Process Argv | –force-user-env --no-sandbox --unity-launch --no-sandbox --crash-reporter-id faba7d7b-2fa9-4f50-9547-77949d63445b |
Screen Reader | no |
VM | 0% |
DESKTOP_SESSION | ubuntu |
XDG_CURRENT_DESKTOP | Unity |
XDG_SESSION_DESKTOP | ubuntu |
XDG_SESSION_TYPE | wayland |
Extensions (8)
Extension | Author (truncated) | Version |
---|---|---|
gitlens | eam | 11.4.1 |
python | ms- | 2021.4.765268190 |
jupyter | ms- | 2021.5.745244803 |
cpptools | ms- | 1.3.1 |
es6-css-minify | olb | 3.3.2 |
material-icon-theme | PKi | 4.6.0 |
LiveServer | rit | 5.6.1 |
material-theme | zhu | 3.10.13 |
(1 theme extensions excluded)
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspyt653:30270858
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vstry914:30276682
pythonvsdeb440:30248342
pythonvsded773:30248341
pythonvspyt875:30259475
pythonvspyt639:30291489
pythontb:30283811
vspre833cf:30267465
pythonptprofiler:30281270
vshan820cf:30276953
pythondataviewer:30285071
vscus158:30286553
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 133
- Comments: 76 (4 by maintainers)
Commits related to this issue
- fix: Fix tsconfig error on file delete/rename https://github.com/microsoft/TypeScript/issues/43838 — committed to fkopp81/currency-frontend by fkopp81 2 years ago
I was able to avoid this issue by restarting the typescript server (in vscode:
Ctrl+Shift+p
->Typescript: Restart TS Server
). I would prefer a proper solution tough.Actually reopening vscode will fix this, but it’s really really annoying tho, that’s why I opened this issue.
I always have this error when moving unused
*.ts
files to another folder or deleting them.I have to kill and re-run
npm start
to make it work againFollowing. I had a similar issue come up after duplicating a .tsx file and then renaming the copy.
Renaming a file causes the same problem too, I need to restart it, which takes nearly a minute, so pretty annoying
Edit: @ArtyomSevyan Solved the problem for me:
Changing
"include": ["src"]
to"include": ["src/**/*"]
in tsconfig.json helped.I am not able to repro this with simple delete or file move… Can you create a small repro project and list the steps (where are you moving file or which file are you deleting) Also sharing
tsserver.log
would be very helpful. Thanks You can upload logs by following these steps:"typescript.tsserver.log": "verbose"
TypeScript: Open TS Server log
commandtsserver.log
. Please share this file. Additionally you can also share fileti.log
created next to it.Thanks! This method works for me, however I hope this issue could be fixed asap (this issue has been opened for 5 months) since it’s really annoying, especially for the early dev. I’ve been spending around 2 hours and finally found this issue though. Thanks!
2 years later still happening. When changing the file name. Restarting TS Server fixed it.
I can live with this as this problem only pops once in a while.
I have a small solution (just to not need
npm start
again):But still, if you are working on vscode, the tsconfig.json file will show error, which is just distracting
This is usually an import error. Make sure the module is being imported correctly!
I’m also having the same problem. The general steps I took is as follows: 1- Setup a project with
npx create-react-app . --template typescript
2- Setuptailwindcss
3- Delete some boilerplate files, includingApp.test.tsx
, which was the source of the error. 4- tsconfig.json
shows an error stating that:My first guess was that it may have something to do with the changes not being committed, but git commit didn’t help. Then I simply closed and reopened vs code and everything was fine. It seems that vs code is referring to some stale cache. I’m on an Ubuntu focal with vs code 1.57.1
I can try to reproduce the error and give more detailed steps if it helps. Although it may heavily depend on context and difficult to reproduce.
This worked for me. Thanks a lot !!
What solved for me:
npm install --save-dev tsconfig-paths
package.json
"baseUrl": "."
and append every single folder to your paths, like:Finally, just run the following: npm run dev
We’ve encountered this error, while deleting files or moving branches (React project). Imports also haven’t worked in newly-created files (Had to restart TS server).
Changing
"include": ["src"]
to"include": ["src/**/*"]
in tsconfig.json helped. No errors so far.I think the proper way to solve this, is trying to change tsconfig.json by putting
"include": ["src/**/*.ts(x)"]
The following is super quick and worked for me (I’m running an expo project):
tsconfig.json
"strict":
fromtrue
tofalse
"strict:
back totrue
and saveexample tsconfig.json below:
I just had this issue come up. I was able to resolve it by
Shift+Ctrl+P > Restart TS Server > adding a dummy function
thenrollup
and it was resolved. I removed the dummy function and now it’s working.Restart vscode is just a stupid action, especially you got multiple tasks running. The
TypeScript: Restart TS Server
is a better solution although it’s not a perfect solution, fixing the problem from the core would be much better, cuz you know, restarting the TS server needs some seconds (sometimes minutes) to get it restarted.I was looking for the solution then I was told just close your VScode and reopen it, the error is gone now. All my expectations that it would be a bug have gone in vain, It sucks.
Heads up that modifying your
tsconfig.json
file will cause the TypeScript language server to automatically restart. So it’s unlikely these issues are fixed by just changing theinclude
. The TypeScript team needs to fix this issue.This worked perfectly for me, thank you
bump
The default is ** so I think this wouldn’t really do anything.
I think I found a easy solution. just make some change in tsconfig.json and return the change. In my case “baseUrl” : “./”, -> “.” <- solved here but I want to return it “baseUrl” : “./”
You can repro this bug by these steps:
electron-quick-start
main.js
tomain.ts
main
value onpackage.json
tomain.ts
hello.ts
Code forhello.ts
:preload.js
file add these line:test
, movehello.ts
into the folder, update import on thepreload.js
filetsserver.log ti-66130.log
I’m experiencing this error only in WSL2. It may not be related, but VSCode also seems unable to automatically fix imports of files that were renamed or moved if you are using TS path aliases. If you are not using path aliases the
updateImportsOnFileMove
seems to work ok but the error intsconfig.json
still shows up, but in this case is more an annoyance than a problem. On Windows 10 or Ubuntu as main SO these errors don’t show up at all.Main SO: Windows 10 Development SO: Ubuntu 22.04.3 LTS (WSL2)
Test cases:
If I’m using WSL but not using TS path aliases, this error pops up and VSCode prompts me to automatically fix import paths. Accepting the changes makes VSCode automatically fix the imports to reflect my changes.
If I’m using WSL and using TS path aliases, this errors pops up and VSCode doesn’t prompt me to automatically fix import paths. Import paths remain broken.
If I use Windows 10 but not TS using path aliases, the error doesn’t appear, and VSCode prompts me to automatically fix import paths. Accepting the changes makes VSCode automatically fix the imports to reflect my changes.
If I use Ubuntu 22.04.3 from another machine without TS path aliases, the error doesn’t appear, and VSCode prompts me to automatically fix import paths. Accepting the changes makes VSCode automatically fix the imports to reflect my changes.
Different potential solutions summary:
tsconfig.json
Bump
I encountered the same problem after renaming files and folders. Restarting TS Server mentioned by lucasbasquerotto worked for me
Happened to me all day and Google gave me this thread. I’m so sad this has no solution other than “edit ts.config.json and undo” someone above posted.
aaaaa oh no, my mistake. I should I have read a bit closer. Went a little blind with annoyance from thinking I had to reinstall the project again 😄 Thanks for the heads up, though, that’s really helpful to know
The same hapening to me here.
Hey all, I found a temporary workaround that solves this problem without needing to change your includes or restart the TypeScript server. In your
tsconfig.json
:This issue is happening because of the way TypeScript handles file system events (
useFsEvents
is the default). It’s unfortunate, but with this method you no longer need to downgrade to a previous version and you’ll no longer need to restart VSCode or your TypeScript tasks.Edit: this temporary workaround only works when you’re creating new files; it doesn’t work if the file is renamed or is no longer available.
this solved for me
Should be put on Backlog milestone. Assigning the OP was a good joke but now lets be honest, this is not making it into 5.3.0. I’m glad to be proven wrong, but so far DX seems to be one of the lowest priorities.
thanks its working for me 😃
Keep in mind that if you restart VSCode, you lose your undo/redo history, so for that reason it’s probably better to restart just the TS server instead.
Either way, on the scale of annoyance this is probably a 1/10, but would love to see this fixed eventually.
Had the same issue, hope it can be solved soon. In the meantime restarting VSCode solves the issue
Had the same issue, but I got it to get away by reloading my Developer Window on VS Code 🙌
For the moment I have changed my keybindings (using VS Code) and I think I will be using them often so I will probably change them again…
It remaps some default keybindings, You probably need something similar depending on your workflow…
Also mentioned in #46432
Did you try that? because
** != **/*
Hey, Just add
"include" : ["**/*"]
after “compilerOptions”, it works fine for me 😃