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

Newly created files don't belong to typescript project on MacOS #45721

Closed
yifanwww opened this issue Sep 4, 2021 · 19 comments Β· Fixed by #47418
Closed

Newly created files don't belong to typescript project on MacOS #45721

yifanwww opened this issue Sep 4, 2021 · 19 comments Β· Fixed by #47418
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@yifanwww
Copy link

yifanwww commented Sep 4, 2021

Bug Report

πŸ”Ž Search Terms

Maybe ts, vscode, file is not part of ts project, newly created?

πŸ•— Version & Regression Information

Tested on the following typescript versions:

  • 4.5.0-dev.20210904
  • 4.4.2
  • 4.4.1-rc
  • 4.3.5

vscode version: 1.60.0

⏯ Playground Link

https://github.com/yifanwww/ts-bug-repo

This is a very simple project...

πŸ™ Actual behavior

Open that project via vscode(whatever open folder directly or open the workspace file).
Open the file src/index.ts to get tsserver started, then create a new file src/test.ts.

There should be an error cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.ts(1208), but actually it got no error.

Execute vscode command Typescript: Go to Project Configuration, a panel appears with info File is not part of a Typescript project. Click here to learn more.

In that new ts file, no auto-completion and no auto-import to use the function fn which is declared in src/index.ts.

I have to restart tsserver or reload vscode.

I have checked these issues but still don't know how to solve this problem.

This bug never happens on my win laptop, but does always happen on my mac laptop.

πŸ™‚ Expected behavior

The file gets added into the existing typescript project.

BTW, If you need tsserver.log, please tell me how to get it.

@DanielRosenwasser DanielRosenwasser added Needs Investigation This issue needs a team member to investigate its status. Needs More Info The issue still hasn't been fully clarified labels Sep 5, 2021
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.5.1 milestone Sep 5, 2021
@orblazer
Copy link

orblazer commented Oct 3, 2021

Hello,
I have exactly same issue but on Linux, but i have found the problem and an temporary solution.

The problem come from include property in tsconfig.json when that property is set to folder or too ambigu in that case src(but this is same if is set to src/**/*).
My solution its stupid but simply specify file type src/**/*.ts.

Thanks.

@yifanwww
Copy link
Author

yifanwww commented Oct 4, 2021

@orblazer Thanks a lot, seems this temporary solution works for me.

@andrewbranch andrewbranch added the Rescheduled This issue was previously scheduled to an earlier milestone label Dec 7, 2021
@andrewbranch
Copy link
Member

Hmm, I can’t reproduce this. I’m on macOS 12.1 Beta, VS Code 1.63.0-insider, and TypeScript 4.4.2 (also tried latest nightly). How are you creating/opening the new file test.ts in your repro instructions? If this is still happening for you, can you post a TS Server log (instructions)? Thanks!

@yifanwww
Copy link
Author

@andrewbranch
I usually click this button to create a new file, name it and then save it.
image

I'm now on macOS 11.6.1, VSCode 1.63.2, and TypeScript 4.5.4, that problem still occurs to me.

I will try to get a tsserver log.

@yifanwww
Copy link
Author

@andrewbranch
BTW, I read the tsconfig reference again (https://www.typescriptlang.org/tsconfig#include).
I want to know is it allowed to set the include option without any glob patterns, like "include": ["src"]?

It seems that "include": ["src"] and "include": ["src/**/*"] behave the same on my win but not on my mac.

@lgarron
Copy link

lgarron commented Dec 29, 2021

I'm also seeing the same issue for the last few... weeks?

It's especially annoying during branch switches, because any files that were moved/created/deleted between the branches will be subject to this bug.

My solution its stupid but simply specify file type src/**/*.ts.

Thanks, this trick saved me a lot of time!
If anyone is trying this workaround, I recommend restarting VSCode rather than just restarting the TypeScript server. That helped it stick for me.

lgarron added a commit to cubing/cubing.js that referenced this issue Dec 29, 2021
Use wildcard paths to include all TS/JS files in the source folders. This ensures that VSCode recognizes new files, indexes them, and allows e.g. ESLint to recognize them.

Workaround from @orblazer at microsoft/TypeScript#45721
lgarron added a commit to cubing/cubing.js that referenced this issue Dec 29, 2021
…source folders.

This ensures that VSCode recognizes new files, indexes them, and allows e.g. ESLint to recognize them.

Workaround from @orblazer at microsoft/TypeScript#45721
@andrewbranch
Copy link
Member

It seems that "include": ["src"] and "include": ["src/**/*"] behave the same on my win but not on my mac.

I thought these were the same. And I still can’t reproduce the issue. @lgarron are you still able to reproduce this if you revert changing the glob format?

Another issue about glob weirdness, though perhaps ultimately unrelated: #46788

@yifanwww
Copy link
Author

@andrewbranch
Hello, here are my tsserver logs https://gist.github.com/yifanwww/f06c9ee62260140f0cca0433bab457c7

There are two files tsserver-1.log and tsserver-2.log, the first one was generated when includes was set as src, and the other one was generated when includes was set as src/**/*. Seems there are huge differences.

@yifanwww
Copy link
Author

yifanwww commented Jan 11, 2022

So in vsocde, select tsserver-1.log for compare then compare tsserver-2.log with selected.

The first difference comes from line 42+, tsserver-2 will watch /ts-bug-repo/src while tsserver-1 won't do that.
image

So when I created test.ts and opened it, tsserver-2 knew it but tsserver-1 only knew that I opened a new file.
image

Then... I don't know what does the other difference mean.

@lgarron
Copy link

lgarron commented Jan 11, 2022

I thought these were the same. And I still can’t reproduce the issue. @lgarron are you still able to reproduce this if you revert changing the glob format?

Indeed:

  • Create a new file β‡’ recognized.
  • Remove the globs and restart VSCode.
  • Create a new file (adjacent to the last time) β‡’ NOT recognized. 🧐

@lgarron
Copy link

lgarron commented Jan 11, 2022

For what it's worth, I'm also able to repro in Codespaces using https://github.com/cubing/cubing.js/tree/exclude-glob-for-ts45721

src/sites/experiments.cubing.net/cubing.js/stub/index.ts supports autocompletion:

Screen Shot 2022-01-10 at 20 08 35

If I create a copy of the file at src/sites/experiments.cubing.net/cubing.js/stub/index2.ts, it does not:

Screen Shot 2022-01-10 at 20 11 46

If I go back to a commit with the globs and restart the TS server, then it works again. So it's quite reproducible for our repo.

@andrewbranch andrewbranch removed the Needs More Info The issue still hasn't been fully clarified label Jan 11, 2022
@andrewbranch
Copy link
Member

I can reproduce in Codespaces and have traced the likely root cause down to the huge differences between file watching on Linux vs. other OSes. This does not explain your observations of it being broken on macOS, which I still can’t reproduce πŸ€”

@andrewbranch
Copy link
Member

Actually, to clarify, in Codespaces I’m seeing the bad behavior all the time. I haven’t yet seen why this would depend on the glob format.

@andrewbranch
Copy link
Member

Discovered with much help from @lgarron that there is an issue when the absolute path to an include pattern contains a . character. @yifanwww, does your repo or any ancestor directory have a .?

@yifanwww
Copy link
Author

@andrewbranch No . character in the repo but yup the home directory in my mac has a . character, that is my name fan.yi.

@andrewbranch
Copy link
Member

Welp, that’s why your repro was not a repro for me πŸ˜… Fixed at #47418

@divmgl
Copy link

divmgl commented Dec 30, 2023

This problem seems to have returned in the latest version of TypeScript and VSCode.

@zburgermeiszter
Copy link

zburgermeiszter commented Jan 5, 2024

This problem seems to have returned in the latest version of TypeScript and VSCode.

It is indeed.
The only fix is to restart TS Server manually, which is not ideal.

Version: 1.85.1 (Universal)
Commit: 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2
Date: 2023-12-13T09:48:06.308Z
Electron: 25.9.7
ElectronBuildId: 25551756
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin arm64 21.6.0
image

tsconfig.json:

{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
    "jsx": "react-jsx",
    "strict": true,
    "target": "es6",
    "module": "esnext",
    "baseUrl": "src",
    "paths": {
      "@components/*": ["components/*"],
      "@context/*": ["context/*"],
      "@gql/*": ["gql/*"],
      "@hooks/*": ["hooks/*"],
      "@pages/*": ["pages/*"],
      "@styles/*": ["styles/*"],
      "@types/*": ["types/*"],
      "@utils/*": ["utils/*"],
      "@SVGs/*": ["SVGs/*"]
    }
  }
}

@RyanCavanaugh
Copy link
Member

There are many reasons this can happen and it depends a lot on your configuration. Please log new issues(s) with concrete repro steps.

@microsoft microsoft locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants