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

tsserver does not seem to respect any of the exclude or watch options #46207

Closed
vikigenius opened this issue Oct 4, 2021 · 3 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@vikigenius
Copy link

vikigenius commented Oct 4, 2021

Bug Report

🔎 Search Terms

tsserver exclude watch

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Common "Bugs" That Aren't Bugs and Common Feature Requests

💻 Code

Here is my tsconfig.json

{
  "include": ["src", "types"],
  "exclude": ["node_modules"],
  "compilerOptions": {
    "module": "esnext",
    "target": "esnext",
    "moduleResolution": "node",
    "jsx": "preserve",
    "baseUrl": "./",
    /* paths - import rewriting/resolving */
    "paths": {
      // If you configured any Snowpack aliases, add them here.
      // Add this line to get types for streaming imports (packageOptions.source="remote"):
      //     "*": [".snowpack/types/*"]
      // More info: https://www.snowpack.dev/guides/streaming-imports
    },
    /* noEmit - Snowpack builds (emits) files, not tsc. */
    "noEmit": true,
    /* Additional Options */
    "strict": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "allowSyntheticDefaultImports": true,
    "importsNotUsedAsValues": "error",
    "noUnusedLocals": false
  },
  "watchOptions": {
    // Use native file system events for files and directories
    "watchFile": "useFsEvents",
    "watchDirectory": "useFsEvents",
    // Poll files for updates more frequently
    // when they're updated a lot.
    "fallbackPolling": "dynamicPriority",
    // Don't coalesce watch notification
    "synchronousWatchDirectory": true,
    // Finally, two additional settings for reducing the amount of possible
    // files to track  work from these directories
    "excludeDirectories": ["node_modules", "_build"],
    "excludeFiles": ["build/fileWhichChangesOften.ts"]
  }
}

You can check the number of file watcher using the following command in Linux
find /proc/*/fd -user "$USER" -lname anon_inode:inotify -printf '%hinfo/%f\n' 2>/dev/null | xargs cat | grep -c '^inotify'
Check before and after you open a folder in your editor.

🙁 Actual behavior

I have tried various options suggested in https://www.typescriptlang.org/docs/handbook/configuring-watch.html and https://www.typescriptlang.org/docs/handbook/tsconfig-json.html for excluding the node_modules folder.

But the moment I open vscode or any editor using tsserver (I tested Emacs and Vim) the number of file watchers increases to 5000. Despite me having only 1 source file. Obviously it includes the node_modules folder.

Using any of the options provided by the editors to exclude folders doesn't work. But that is expected because they can't control what files tsserver is watching. They can just hide any problems that are reported.

🙂 Expected behavior

tsserver should respect the exclude options in tsconfig.json and not include node_modules.

@MartinJohns
Copy link
Contributor

Are you importing any modules? Exclude does not prevent inclusion when they're imported.

@vikigenius
Copy link
Author

vikigenius commented Oct 6, 2021

@MartinJohns Deleting every single file in the src folder and creating a new file with nothing imported also gives me 4592 inotify watchers.

The typescript compiler tsc does respect the watch exclude options. Using tsc --watch without the watch exclude options creates 4588 inotify watchers. But with the watch exclude options, it creates only 206.

tsserver, with or without the watch exclude options creates 4598 inotify watchers. Clearly indicating that it is including every single node_modules file and ignoring the options.

@andrewbranch
Copy link
Member

Duplicate of #46351

@andrewbranch andrewbranch marked this as a duplicate of #46351 Oct 20, 2021
@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants