Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kimlimjustin opened this issue Apr 24, 2021 · 81 comments
Assignees
Labels
Bug A bug in TypeScript Needs More Info The issue still hasn't been fully clarified Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@kimlimjustin
Copy link

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 mjbvz transferred this issue from microsoft/vscode Apr 26, 2021
@mjbvz mjbvz removed their assignment Apr 26, 2021
@mjbvz
Copy link
Contributor

mjbvz commented Apr 26, 2021

Please share your tsconfig and a overview of your project structure

@kimlimjustin
Copy link
Author

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.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Apr 27, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.4.0 milestone Apr 27, 2021
@sheetalkamat
Copy link
Member

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.

@sheetalkamat sheetalkamat added the Needs More Info The issue still hasn't been fully clarified label May 10, 2021
@kimlimjustin
Copy link
Author

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
Copy link

anandvc commented Jun 23, 2021

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

@Ark-kun
Copy link

Ark-kun commented Jun 25, 2021

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
Copy link

The same hapening to me here.

@alirezaghey
Copy link

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
Copy link

Versiani-R commented Jul 7, 2021

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

@kimlimjustin
Copy link
Author

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
Copy link

koltday commented Jul 14, 2021

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

@lucasbasquerotto
Copy link

lucasbasquerotto commented Jul 16, 2021

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.

@andrewbranch andrewbranch added the Rescheduled This issue was previously scheduled to an earlier milestone label Aug 30, 2021
@kimlimjustin kimlimjustin removed their assignment Sep 10, 2021
@stanleyowen
Copy link

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
Copy link

sahin52 commented Sep 10, 2021

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
Copy link

sahin52 commented Sep 12, 2021

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

@jpausa
Copy link

jpausa commented Mar 21, 2023

Had the same issue, hope it can be solved soon. In the meantime restarting VSCode solves the issue

@slacle
Copy link

slacle commented Apr 6, 2023

2 years later still happening. When changing the file name. Restarting TS Server fixed it.

@virtuallyunknown
Copy link

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.

@Sharjeel-22
Copy link

"include" : ["**/*"]

thanks its working for me :)

@wpyoga
Copy link

wpyoga commented Jun 18, 2023

@alanvitalp 's solution:

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

Doesn't work for me. I'm on TypeScript 5.1.3 .

@PiyushDuggal-source 's solution:

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

Doesn't work for me either.

@linonetwo
Copy link

{
  "extends": "../../tsconfig.json",
  "include" : ["./src/**/*"],
  "compilerOptions": {
    "rootDir": "./src"
  }
}

works for me.

SukkaW/rollup-plugin-swc#35 (comment)

@slince-zero
Copy link

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!

Thanks, I've been troubled by this question for a long time, it's useful

@matjaeck
Copy link

matjaeck commented Sep 7, 2023

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.

@Revan99
Copy link

Revan99 commented Oct 4, 2023

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

@mohamedsaleh1984
Copy link

It's very crazy, I have a lot to finish and I can continue like this.
It's crazy. Is there any solution ??

@Leonelmarianog
Copy link

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.

@artilishes
Copy link

artilishes commented Jan 18, 2024

I solved it by adding "**/*" to my tsconfig's include and setting up the excludes properly.

...
"include": [
    "next-env.d.ts",
    "next.config.js",
    "**/*.ts",
    "**/*.tsx",
    ".next/types/**/*.ts",
    "./*.config.js",
    "**/*",
  ],
  "exclude": ["node_modules", "build"],
  ...

@navjotSingh2000
Copy link

I fixed it by deleting the component's file that I was importing using Finder, then going back to the VS CODE and then creating that file again using Finder

@divmgl
Copy link

divmgl commented Jan 27, 2024

The **/* or src/**/* fixes do not work in my project.

Creating a new file, renaming a file or deleting a file will crash the TypeScript --watch server and require me to restart it:

[6:18:16 AM] File change detected. Starting incremental compilation...

error TS6053: File '/Users/dimiguel/dev/packages/app/src/posthog.ts' not found.
  The file is in the program because:
    Matched by include pattern '**/*' in '/Users/dimiguel/dev/packages/app/tsconfig.json'

  packages/app/tsconfig.json:13:15
    13   "include": ["**/*"],
                     ~~~~~~
    File is matched by include pattern specified here.

[6:18:19 AM] Found 1 error. Watching for file changes.

This is causing other issues, such as new files not being detected inside of a project.

Would really appreciate a fix for this as I'm having to constantly restart my TypeScript server and all related tasks for new files, file renames and deleted files.

@divmgl
Copy link

divmgl commented Jan 27, 2024

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.

@Virtute90
Copy link

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

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

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

@divmgl
Copy link

divmgl commented Jan 31, 2024

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.

@ShahabDadKhan
Copy link

ShahabDadKhan commented Feb 6, 2024

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.

@Prem-Dharshan
Copy link

I had a similar issue

File 'd:/Tutorials/ProLeap/proleap-backend/src/users/entities/user0session.entity.ts' not found.
  The file is in the program because:
    Matched by default include pattern '**/*'ts
JSON schema for the TypeScript compiler's configuration file

This happened when I cancelled the popup by VSC which asked refactor the imports?. I simply ignored it and that resulted in this error.

Solution:
I re-created the file user0session.entity.ts and then deleted it correctly. The error was gone like magic.

Probably in your case, copy the contents and delete the config file. Re-create it with the same contents.

Hope this helps.

@danilofuchs
Copy link

danilofuchs commented Jun 21, 2024

Enabling
typescript.tsserver.experimental.useVsCodeWatcher: true and typescript.tsserver.experimental.enableProjectDiagnostics: true at the same time causes this error.

My solution: Set typescript.tsserver.experimental.useVsCodeWatcher: false

@virtuallyunknown
Copy link

Update to Typescript 5.5, it fixes this problem. The current version of VSCode ships with Typescript 5.4.5, however you can easily change it to use the "workspace" version, assuming you have installed latest Typescript in your project.

Open the command palette (ctrl+shift+p) -> Typescript: Select Typescript Version.

#58120 (I think).

@uphiago
Copy link

uphiago commented Jun 27, 2024

We can just update it in VSCode, as @virtuallyunknown mentioned. This should fix the problem.

"devDependencies": {
    "typescript": "^5.5.2"
  }

2024-06-27_09-53

@sheetalkamat
Copy link
Member

If you are still facing issues after updating to typescript@latest or typescript@next , please open new issue as this one is old and things have changed since then,.

We need clear repro steps and tsserver log when you open the issue to be able to investigate it.
Thanks

Rolling Work Tracking automation moved this from Not started to Done Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Needs More Info The issue still hasn't been fully clarified Rescheduled This issue was previously scheduled to an earlier milestone
Projects
Development

No branches or pull requests