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

Most upvoted comments

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.

Good to know I’m not alone! Thought this was a problem with CRA-TypeScript. I did find (someone else’s solution which I scoured upon) that deleting node-modules and then running “yarn” or “npm install” to reinstall them will fix it. A huge pain though, especially with large projects on a slower/older computer…

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.

TypeScript error in undefined(undefined,undefined):
File '<path>/pipeline-editor/src/DragNDrop/Sidebar copy.tsx' not found.
  The file is in the program because:
    Matched by include pattern 'src' in '<path>\pipeline-editor\tsconfig.json'  TS6053

I have to kill and re-run npm start to make it work again

Following. 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:

  1. Set "typescript.tsserver.log": "verbose"
  2. Restart vscode or vscode insiders
  3. Reproduce the problem
  4. In vscode or vscode insiders, run the TypeScript: Open TS Server log command
  5. This should open a large file called tsserver.log. Please share this file. Additionally you can also share file ti.log created next to it.

I was able to avoid this issue by restarting the typescript server (in vscode: Ctrl+Shit+p -> Typescript: Restart TS Server). I would prefer a proper solution tough.

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 was able to avoid this issue by restarting the typescript server (in vscode: Ctrl+Shit+p -> Typescript: Restart TS Server). I would prefer a proper solution tough.

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):

  • go to tsconfig.json
  • delete “src” string in “include” array and save
  • undo and save (get back to normal state, “src” string must come back)
  • in your project’s src directory, save any file. It will compile succesfully

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- Setup tailwindcss 3- Delete some boilerplate files, including App.test.tsx, which was the source of the error. 4- ‍tsconfig.json shows an error stating that:

File '%PROJECT_ROOT/src/App.test.tsx' not found.
  The file is in the program because:
    Matched by include pattern 'src' in '%PROJECT_ROOT/tsconfig.json'ts

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.

I was able to avoid this issue by restarting the typescript server (in vscode: Ctrl+Shit+p -> Typescript: Restart TS Server). I would prefer a proper solution tough.

This worked for me. Thanks a lot !!

What solved for me:

  1. npm install --save-dev tsconfig-paths
  2. package.json
"scripts": {
    "dev": "ts-node-dev -r tsconfig-paths/register src/main.ts"
}
  1. In your tsconfig.json, set "baseUrl": "." and append every single folder to your paths, like:
"baseUrl": ".",
"paths": {
    "controllers/*": [ "./src/controllers/*" ],
    "helpers/*": [ "./src/helpers/*" ],
    "utils/*": [ "./src/utils/*" ],
    "components/*": [ "./src/components/*" ],
    "interfaces/*": [ "./src/interfaces/*" ],
    "middlewares/*": [ "./src/middlewares/*" ],
    "models/*": [ "./src/models/*" ],
    "routes/*": [ "./src/routes/*" ],
    "services/*": [ "./src/services/*" ],
    "validations/*": [ "./src/validations/*" ]
}

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).

Failed to compile.

undefined
TypeScript error in undefined(undefined,undefined):

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):

  1. Open tsconfig.json
  2. Change "strict": from true to false
  3. save the file (error goes away)
  4. Change "strict: back to true and save
  5. Move on with your life

example tsconfig.json below:

{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
    "strict": true  // This is where you (2) change strict from TRUE to FALSE, (3) save, (4) change it back to true and save
  }
}

I just had this issue come up. I was able to resolve it by Shift+Ctrl+P > Restart TS Server > adding a dummy function then rollup and it was resolved. I removed the dummy function and now it’s working.

restart vscode

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.

Good to know I’m not alone! Thought this was a problem with CRA-TypeScript. I did find (someone else’s solution which I scoured upon) that deleting node-modules and then running “yarn” or “npm install” to reinstall them will fix it. A huge pain though, especially with large projects on a slower/older computer…

Actually reopening vscode will fix this, but it’s really really annoying tho, that’s why I opened this issue.

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.

I solved the problem with this modification (in linux environment):

"include": ["src/**/*.ts", "src/js/**/*.tsx"]

to "include": ["./src/**/*.ts", "./src/js/**/*.tsx"]

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 the include. The TypeScript team needs to fix this issue.

I was able to avoid this issue by restarting the typescript server (in vscode: Ctrl+Shit+p -> Typescript: Restart TS Server). I would prefer a proper solution tough.

This worked perfectly for me, thank you

bump

Hey, Just add "include" : ["**/*"] after “compilerOptions”, it works fine for me 😃

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:

  1. Clone the electron-quick-start
  2. Change main.js to main.ts
  3. Edit the main value on package.json to main.ts
  4. Create a new file called hello.ts Code for hello.ts:
    const Hello = () => {
       return "Hello World"
    }
    
    module.exports = Hello
    
  5. Inside the preload.js file add these line:
    const hello = require('./test/hello.ts')
    hello()
    
  6. Create a new folder called test, move hello.ts into the folder, update import on the preload.js file
  7. Problem occurs

tsserver.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 in tsconfig.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:

  1. 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.

  2. 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.

  3. 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.

  4. 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:

  • Restarting TS Server ctrl+shift+P : restart ts server
  • Restarting VSCode
  • Adding different src variations to 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.

Good to know I’m not alone! Thought this was a problem with CRA-TypeScript. I did find (someone else’s solution which I scoured upon) that deleting node-modules and then running “yarn” or “npm install” to reinstall them will fix it. A huge pain though, especially with large projects on a slower/older computer…

Actually reopening vscode will fix this, but it’s really really annoying tho, that’s why I opened this issue.

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:

{
  "watchOptions": {
    "watchFile": "fixedpollinginterval" // or "dynamicPriorityPolling"
  }
}

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.

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.

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.

“include” : [“**/*”]

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…

Screenshot_000001_20221201_092230

It remaps some default keybindings, You probably need something similar depending on your workflow…

Also mentioned in #46432

Hey, Just add "include" : ["**/*"] after “compilerOptions”, it works fine for me 😃

The default is ** so I think this wouldn’t really do anything.

Did you try that? because ** != **/*

Hey, Just add "include" : ["**/*"] after “compilerOptions”, it works fine for me 😃