microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.07k stars 12.37k forks source link

Tsconfig show typescript file not found error after moving it to another directory or delete it. #43838

Closed kimlimjustin closed 2 months ago

kimlimjustin commented 3 years ago

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 ```
mjbvz commented 3 years ago

Please share your tsconfig and a overview of your project structure

kimlimjustin commented 3 years ago

It's an electron project, structure:

...
├── node_modules
├── src                          # Source code
│   ├── config                 
│           ├── theme.json
│   ├── drives.ts
│   ├── main.ts
│   ├── preload.js
│   ├── theme.js
├── package-lock.json
├── package.json
├── README.md
└── tsconfig.json

My tsconfig.json file is generated by tsc --init command.

sheetalkamat commented 3 years ago

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.
kimlimjustin commented 3 years ago

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

anandvc commented 3 years ago

Following. I had a similar issue come up after duplicating a .tsx file and then renaming the copy.

Ark-kun commented 3 years ago

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

LuisAlejandro commented 3 years ago

The same hapening to me here.

alirezaghey commented 3 years ago

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.

Versiani-R commented 3 years ago

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

kimlimjustin commented 3 years ago

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.

koltday commented 3 years ago

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 :smile: Thanks for the heads up, though, that's really helpful to know

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

stanleyowen commented 2 years ago

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!

sahin52 commented 2 years ago

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.

sahin52 commented 2 years ago

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

ecorona commented 2 years ago

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.

igorer88 commented 2 years ago

It happens to me too. :disappointed:

fpmanuel commented 2 years ago

Same here :(

crackedpotato007 commented 2 years ago

Same here ;(

bviala commented 2 years ago

bump

mkmladja commented 2 years ago

Another one...

adobrov-arcadia commented 2 years ago

Pretty annoying, yeah...

Mazata commented 2 years ago

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

Do you have to do this everytime you rename/move/delete a file or does this solution carry some longevity?

michaelezehi commented 2 years ago

I think I figure out why this happens. When you rename through your IDE. In some cases it does not rename the folder correctly. This causes this issue. I went to view my folder in viewer and there it was, the old name hadn't changed.

In summary, renaming inside VS code caused this issue for me. Try renaming through your folder directory.

sandersn commented 2 years ago

I tried to repro with @kimlimjustin 's instructions and @alirezaghey 's but couldn't cause get either repro to work? Can anybody provide more detailed instructions?

I looked at @kimlimjustin 's tsserver log and could see test.ts get noticed by the language service and then get added to the tsconfig via the **/*. But I couldn't see where the move into the test folder happened. Does this only happen when you use VS Code's file management controls? If so, can you describe how to do that step-by-step? I'm not used to using them so I probably missed a step when trying to repro it on my own.

vitustockholm commented 2 years ago

tried to turn off this error but still vs code makes it again and again again, just dont want to change vs code, but have this annoying thing error TS6053: File 'index.ts' not found.

kimlimjustin commented 2 years ago

I'm not sure why but this does not occur with stable reproducible steps anymore, I mean, using the latest version, the reproducible steps I wrote there months ago do not reproduce again. However, this issue still remains an issue cuz I sometimes got into this problem when working hard on my code (I usually just restart the TS server to make it works), but I got no idea about the reproducible steps. Maybe others?

nichitaa commented 2 years ago

bump

ghost commented 2 years ago

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.

r4hulp commented 2 years ago

Happening to me as well whenever I delete/move/rename files... The temporary solution is to restart TS server but it is not a feasible solution.

kimlimjustin commented 2 years ago

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.

crackedpotato007 commented 2 years ago

For me it was just the ts server being extremely slow, you can run tsc --extendedDiagnostics to diagnose this. Personally mongoose was the package causing this issue. Got rid of it and voila

kimlimjustin commented 2 years ago

Personally mongoose was the package causing this issue. Got rid of it and voila

I don't have mongoose in my project and this issue sometimes occur when I operate large operation (ex: switching branch with different project dependencies and different structure , usually when switching to refactoring branch), hence I can't really write a reproducable steps as its quite impossible to test the large operation.

Shomme commented 2 years ago

+1 I hate and curse this issue. Happens on WebStorm with big project, Typescript service reset doesn't help, the only way was to fully restart application, which takes minutes... Found a way in this topic through editing tsconfig, but i feel like Im an idiot when I do it, and anyway it takes too much attention and time.

ArtyomSevyan commented 2 years ago

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.

feliciakri commented 2 years ago

I encountered the same problem after renaming files and folders. Restarting TS Server mentioned by lucasbasquerotto worked for me

q7y331xk commented 2 years ago

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" : "./"

jespadas commented 2 years ago

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 !!

SHAgility commented 2 years ago

Bump

OswalDev commented 2 years ago

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

PiyushDuggal-source commented 2 years ago

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

JRRS1982 commented 2 years ago

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

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

PiyushDuggal-source commented 2 years ago

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** != **/*

alanvitalp commented 2 years ago

I think the proper way to solve this, is trying to change tsconfig.json by putting "include": ["src/**/*.ts(x)"]

mkaulfers commented 2 years ago

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.

seerviashish commented 2 years ago

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.

This one worked

aminsoraya commented 2 years ago

I have this structure : components/Login/index.tsx How do I handle Error in tsconfig.json file?

Luxcium commented 1 year ago

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

khaled-300 commented 1 year ago

I had the same issue, due to change of version in ts i had the latest version before and for the need in other project of mine i had to downgrade to typescript@4.4.2 and the issue started to happen. It got resolved simply by same way Shift+Ctrl+P > Restart TS Server

DanielRosenwasser commented 1 year ago

It sounds a whole lot like TypeScript 4.8's file-watching fixes and TypeScript 4.9's usage of file system events should alleviate this issue. The 4.8 fix targeted Unix-like systems (including Linux and macOS) if that's relevant to anyone reading this.

So I'm curious to hear if anyone is experiencing this with the latest version of TS.