typescript-eslint: Parser reports "Parsing error" for new files added to project (VSCode)
What code were you trying to parse?
A new React component module. This happens on all new TypeScript source files, however. This is being triggered from the instance of ESLint that VSCode runs in the background, meaning that in order to get this error to go away, I have to reload the entire VSCode window.
import React from "react";
import { EditorProps } from ".";
import { Switch } from "@material-ui/core";
export function AreaListMode( { settings, updateSettings }: EditorProps ) {
return <Switch checked={ settings.areaListStyle } onChange={ e => updateSettings( { areaListStyle: e.target.checked ? "compact" : "default" } ) } />;
}
tsconfig.json include:
"include": [
"projects/*/typings/**/*",
"projects/*/src/**/*"
],
What did you expect to happen?
The file should be parsed normally, as its path is matched by the include property in my tsconfig.json file.
What actually happened? A “Parsing error” is reported on the first line of any file that is created while the VSCode linter instance is running, saying that the file is not included in the project. The error does not go away unless I restart VSCode (or reload the window).

Versions
| package | version |
|---|---|
@typescript-eslint/parser |
2.0.0 |
TypeScript |
3.4.5 |
ESLint |
6.1.0 |
node |
12.7.0 |
~npm~ yarn |
1.17.3 |
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 60
- Comments: 24 (17 by maintainers)
Commits related to this issue
- fix eslint issue https://github.com/typescript-eslint/typescript-eslint/issues/864#issuecomment-523190869 — committed to aereal/musik by aereal 7 years ago
- You just can't win - If we include `test` or `typings` files, we get a compiler error related to https://github.com/Microsoft/TypeScript/issues/9858. - If we exclude (not added to `include`) `test` ... — committed to MaximDevoir/labels-manager by MaximDevoir 7 years ago
- build(lint): fix eslint issue typescript-eslint/typescript-eslint#864 — committed to devexperts/dx-platform by raveclassic 7 years ago
- fix(eslint): add new parser option Parser reports "Parsing error" for new files added to project (VSCode) #864 typescript-eslint/typescript-eslint#864 — committed to Alrefai/next-tip-calc by Alrefai 7 years ago
The workaround is
createDefaultProgram: trueadded toparserOptionsin your eslint config, mentioned in comments about halfway down this page.I’m seeing this behaviour in IntelliJ as well, so I suspect they share a root cause.
I’d image WebStorms handling of TS is similar enough to vscodes that the same fix should work for both, but someone like @prigara would be able to tell you for sure (+ I figure they’d interested in knowing about this issue).
Since there isn’t way to restart the eslint service (WEB-38066 wink wink nudge nudge), I have to open & close the project everytime I add a new file in some places.
No pressure or nothing, but this is actually super annoying 😂
Let me know if there’s anything I can do to help - happy to do testing & what-have-you w/ IntelliJ/WebStorm on my end, and can report an issue on YouTrack if needed 🙂
On a side note: would it be possible/worth having an option to revert back to the pre-2.0.0 behaviour in the meantime?
@bradzacher thanks for the link - I didn’t see that issue, but I did see the
includesthing in the release notes.I’ve confirmed that in this project, running
npm run lintgives:As expected since
srcisn’t included, but WebStorm gives that if I make a new.tsfile inconfigs/, which is included viatsconfig.eslint.json.createDefaultProgram: truefixes this as expected.Let me know if you’d like me to make a new webstorm-specific issue 🙂
Now that the file watching has been added, it should no longer be necessary to use
createDefaultProgram: trueas a way to avoid errors for new files.createDefaultProgram: trueshould be avoided whenever possible as it can mask incorrect file glob configurations by users and leads to potentially huge performance hits on lint runs.not sure if it’s a workaround, exactly, but I use
cmd+shift+pand thenDeveloper: Reload Windowto get it to pick up new files I’ve created. It’s definitely not ideal, but seems way easier than either downgrading or disabling linting.In a nutshell, you’ll probably find that the IDEs use eslint’s internal APIs to trigger a parse of the file based on the file contents the IDE loaded. This is how they do parses whilst you’re still typing without saving!
In the interest of saving time and memory however, the IDE will essentially maintain its NodeJS instance, so as far as our parser is concerned - it’s one big, long, continuous, never ending lint session.
https://eslint.org/docs/developer-guide/nodejs-api#cliengineexecuteontext
I only raised #890 this morning, to try and consolidate the discussion going forward because people were commenting on closed issues.
Yup, it doesn’t matter if it’s via
eslint --watch, or via an IDE plugin - the mechanism is essentially the same. ESLint runs continually, and sends files to our parser.Because eslint never “dies”, our parser maintains its state - you launch the IDE, it starts eslint, which triggers our parser, which triggers typescript and detects all of the valid files matched by your tsconfig.
This is great for existing files, as we only need to do a small bit of work when you update the file.
However with new files, it means that our project state doesn’t contain the brand new file. Unfortunately, we don’t currently have a mechanism for telling typescript to “rescan” the workspace to detect new files. Which means ofc your file just throws an error.
createDefaultProgramessentially allows the parser to use old code path. This means that when the parser detects a file that hasn’t been parsed, it treats it as the root of a new program, and parses the file and its dependencies. Less performant by a long shot, but covers all the bases. The reason that it’s bad turning this function on, is because you could get caught with a slow lint outside of the IDE because you added a file that’s not included in your tsconfig. So yeah, use it with caution! It’ll unblock you fine though.We will figure out how to build the “rescan” functionality above, so that you can turn off
createDefaultProgram.In VS Code, we use TSServer, which handles of the file watching, project creation, and everything else. What we do in typescript-estree is at a lower level in the TS architecture, where we interact directly with the Node API for the TS compiler itself. By stepping up to a higher level of the TS architecture, we’d get more pieces handled for us (including this file watching piece), but may incur more performance overhead.
https://github.com/typescript-eslint/typescript-eslint/blob/master/README.md#package-versions
Automated release schedule is listed in the readme.
@bradzacher this is still occurring in Intellij on the latest 2.4.0 (https://github.com/typescript-eslint/typescript-eslint/releases/tag/v2.4.0) which includes your PR https://github.com/typescript-eslint/typescript-eslint/pull/973
Versions
@typescript-eslint/parser2.4.0TypeScript3.6.4ESLint6.5.1node11.10.1Hey all – just checking in if there’s an ETA or a workaround patch… finding that this error is leading developers to disable linting in their IDEs completely. Should we step down to 1.13 in the meantime or is a fix close? Thanks for all the work on this!
interesting. We should probably look into the mechanisms that the eslint vscode plugin uses to setup its watch mode - maybe there’s something we can listen to to help inform how we watch.