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

vscode-eslint: Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. #1723

Closed
nojvek opened this issue Mar 12, 2020 · 18 comments
Labels
awaiting response Issues waiting for a reply from the OP or another party package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@nojvek
Copy link

nojvek commented Mar 12, 2020

What code were you trying to parse?

// new.ts
console.log(`hello`)l

What did you expect to happen?

no errors

What actually happened?
vscode-eslint yells at me. Running in cli is fine. Only happens for new files.

I know the workaround is to restart vscode but that's like dropping a nuclear bomb to break open a coconut.

I assume it's an issue with watching for changes.

image

Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: common/util/new.ts.
The file must be included in at least one of the projects provided.

Always see this at the start of a new file. Existing files work fine. I assumed this was fixed in new version, but it seems not.

Configs

tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "alwaysStrict": true,
    "baseUrl": ".",
    "checkJs": false, 
    "declaration": false,
    "esModuleInterop": true,
    "jsx": "react",
    "jsxFactory": "h",
    "lib": ["esnext", "dom"],
    "moduleResolution": "node",
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "pretty": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "strictNullChecks": false,
    "target": "es6",
    "typeRoots": ["./node_modules/@types", "./ts-global-types"],
    "paths": {
      "common/*": ["./common/*"],
      "server/*": ["./server/*"]
    }
  },
  "include": ["common/", "frontend/", "server/"]
}

.eslintrc.js

const TS_OVERRIDE = {
  files: [`**/*.ts`, `**/*.tsx`],
  parser: `@typescript-eslint/parser`,
  parserOptions: {
    project: `./tsconfig.json`,
    tsconfigRootDir: __dirname,
  },
  plugins: [`@typescript-eslint`],
  extends: [
    `eslint:recommended`,
    `plugin:@typescript-eslint/eslint-recommended`,
    `plugin:@typescript-eslint/recommended`,
    `plugin:@typescript-eslint/recommended-requiring-type-checking`,
    `prettier`,
    `prettier/@typescript-eslint`,
  ],
  rules: ...
};

module.exports = {
  root: true,
  env: {
    browser: true,
    es6: true,
  },
  extends: `eslint:recommended`,
  overrides: [TS_OVERRIDE],
  parserOptions: {
    ecmaVersion: 2020,
    sourceType: `module`,
    ecmaFeatures: {
      jsx: true,
    },
  },
  plugins: [`react`],
  settings: {
    react: {
      pragma: `h`,
    },
  },
....
}

Versions

    "@typescript-eslint/eslint-plugin": "2.23.0",
    "@typescript-eslint/parser": "2.23.0",
    "typescript": "3.8.3",
    "eslint": "6.8.0",
    node v12.14.0
    npm 6.13.6

Halp!

@nojvek nojvek added package: parser Issues related to @typescript-eslint/parser triage Waiting for team members to take a look labels Mar 12, 2020
@bradzacher
Copy link
Member

Nobody else has reported it, so it's probably something to do with the setup.

could you please set parserOptions.debugLevel: true and then reproduce the bug?
In vscode you can use the command palette to open the eslint logs.
Dump the output here please.

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party package: typescript-estree Issues related to @typescript-eslint/typescript-estree and removed package: parser Issues related to @typescript-eslint/parser triage Waiting for team members to take a look labels Mar 13, 2020
@Akuukis
Copy link

Akuukis commented Mar 23, 2020

I have the same problem, although it's for all files.

$ yarn list --pattern "typescript"
yarn list v1.22.4
├─ @babel/plugin-syntax-typescript@7.8.3
├─ @babel/plugin-transform-typescript@7.8.3
├─ @babel/preset-typescript@7.8.3
├─ @typescript-eslint/eslint-plugin@2.24.0
├─ @typescript-eslint/experimental-utils@2.24.0
├─ @typescript-eslint/parser@2.24.0
├─ @typescript-eslint/typescript-estree@2.24.0
├─ typescript-tslint-plugin@0.5.5
└─ typescript@3.8.3

VSCode Eslint version: 2.1.1

module.exports = {
    root: true,
    parser: '@typescript-eslint/parser',
    plugins: [
        '@typescript-eslint',
    ],
    parserOptions: {
        tsconfigRootDir: __dirname,
        project: ['./tsconfig.json'],
    },
    extends: [
        'eslint:recommended',
        'plugin:@typescript-eslint/eslint-recommended',
        'plugin:@typescript-eslint/recommended',
        'plugin:@typescript-eslint/recommended-requiring-type-checking',
    ],
};

@Akuukis
Copy link

Akuukis commented Mar 23, 2020

I figured it out: I had workspace open via symlinked folder. Once I open workspace at the real folder path it works.

@nojvek
Copy link
Author

nojvek commented Mar 26, 2020

It’s still happening for me @bradzacher, I’ll send you debugLog.

Do you know how the vscode plugin watches for changes and adds new files to compilation context ? I feel that’s where the issue is.

@gavin-gyle
Copy link

This issue is happening for our whole team currently across VSCode and Atom IDEs. Our only solution has been to remove node_modules and reinstall all packages. It usually happens when pulling in new files from Git.

@bradzacher
Copy link
Member

please open a new issue @gavin-gyle and provide as much information as possible.

@nojvek the IDE plugin doesn't do anything - that's handled by our codebase.

@Vishesh30
Copy link

Vishesh30 commented Apr 26, 2020

@bradzacher - We also migrating from tslint to eslint and have started facing the same issue.

We have a Monorepo using "lerna" Our settings.json file has this config to support monorepo:-

"eslint.workingDirectories": [{ "pattern": "./packages/*/" }],

Our tsconfig.json file:-

{
    "compileOnSave": true,
    "compilerOptions": {
        "moduleResolution": "Node",
        "esModuleInterop": true,
        "module": "commonjs",
        "target": "es6",
        "sourceMap": true,
        "alwaysStrict": true,
        "rootDir": "./src",
        "outDir": "./build",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "declaration": true,
        "resolveJsonModule": true,
        "incremental": true,
        "tsBuildInfoFile": "./.tsBuildInfoFile"
    },
    "files": [
        "./src/basis/Global/models/DataTypes.ts",
        "./src/basis/models/DataTypes.ts",
        "./src/basis/Security/models/DataTypes.ts",
        "./src/Metamodel/models/DataTypes.ts"
    ],
    "include": ["./src/**/*"],
    "exclude": ["./node_modules/", "./src/tests/**/*.gen.ts", "./src/**/models/"]

Our eslintrc.js file:-

module.exports = {
    env: {
        browser: true,
        es6: true,
        node: true
    },
    extends: [
        "eslint:recommended",
        "plugin:@typescript-eslint/eslint-recommended",
        "plugin:@typescript-eslint/recommended",
        "prettier",
        "prettier/@typescript-eslint", 
        "plugin:prettier/recommended"
    ],
    parser: "@typescript-eslint/parser", // Specifies the ESLint parser
    parserOptions: {
        ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
        project: "tsconfig.json",
        sourceType: "module",
        createDefaultProgram: true
    },
    plugins: ["@typescript-eslint", "prettier"],
    rules: {
        "@typescript-eslint/interface-name-prefix": "warn",
        "@typescript-eslint/no-inferrable-types": "off",
        "@typescript-eslint/member-ordering": "off",
        "@typescript-eslint/no-use-before-define": "off",
        "@typescript-eslint/no-floating-promises": "warn",
        "@typescript-eslint/no-array-constructor": "warn",
        "@typescript-eslint/no-var-requires": "off",
        "@typescript-eslint/no-empty-function": "warn",
        "@typescript-eslint/camelcase": "warn",
        "@typescript-eslint/no-this-alias": "warn",
        "@typescript-eslint/consistent-type-assertions": "warn",
        "@typescript-eslint/ban-types": "warn",
        "@typescript-eslint/no-namespace": "off",
        "@typescript-eslint/quotes": "off",
        "@typescript-eslint/semi": ["off", null],
        "@typescript-eslint/type-annotation-spacing": "off",
        "@typescript-eslint/class-name-casing": "warn",
        "@typescript-eslint/no-empty-interface": "warn",
        "@typescript-eslint/no-explicit-any": "off"
    },
    settings: {}
};

Let me know in case i have open another issue.

@r3faat1
Copy link

r3faat1 commented Apr 28, 2020

Same issue. Just a simple component:
image

It only shows the issue when no other components import it. As soon as one other component import this, the issue goes away. But why though? We should be allowed to have unused components for future use.

@bradzacher
Copy link
Member

bradzacher commented Apr 28, 2020

As per the error message: You don't have the file included in your tsconfig.

When no file imports it, it is never added to the dependency graph, because it's not in the tsconfig.

When another component imports it, typescript automatically expands the dependency graph to include that file (thereby working around the fact that your file isn't included in your tsconfig).

@r-hannuschka
Copy link

I face the same problem, but this is not a typescript file it is a js file i used for binary (run with npm run wich does some work)

image

So i can include this one but then it is not a ts file and the typescript linter try to lint this one (even if i say allowJS: false.

If i add this to exclude the error is shown up
If i add explicit include: ["./extension/**/*.ts"] the error is shown up

this is like include or die since this file is in the root for tsconfig. Currently do not know how to fix this without change my whole folder structure.

@gavin-gyle

This comment has been minimized.

@bradzacher
Copy link
Member

bradzacher commented May 11, 2020

Do not use that option. It was added as a stop-gap to help people migrate to v2 whilst we ironed out the kinks in the new algorithm.

It has been many months since we rebuilt the algorithms, and it now properly handles all the configurations and adding/removing of files.

As such, createDefaultProgram will be removed in a future version.
Relying upon this flag now will cause you pain in the future.

Additionally using this option will exponentially increase your lint times (this is why we turn that functionality off by default in 2.0).


If you are receiving this error message it means the following:

You are attempting to lint a file (with type aware linting) which is not included in one of the tsconfigs you have passed to parserOptions.project.

Solutions:

  • review the tsconfigs you pass to us to ensure the file is matched by one of the include globs.
  • if the file is not already in a tsconfig because it's in a weird place (like a root "tools" folder or something), then you can simply create a new tsconfig (I usually recommend calling it tsconfig.eslint.json) and include the file there.
  • use eslint overrides to disable type-aware linting for those files (I.e. Unset parserOptions.project).
  • use an .eslintingore file to ignore the file from linting.

Again, and I cannot stress this enough, DO NOT USE createDefaultProgram.

@clehene
Copy link

clehene commented May 22, 2020

@bradzacher

Can you point to the actual documentation on how to set this properly?
In our case we get it for the actual .eslintrc.js

image

@bradzacher
Copy link
Member

@gSarciotto
Copy link

@clehene

I was having the same issue, my project structure is:

project
|-- tsconfig.json
|-- .eslintrc.js
|-- .eslintignore
|-- src

Since I only want to lint the files in src, in my tsconfig.json I have
"include": [ "src/**/*" ]

With this setup, I was getting the same error, so I added .eslint.js in the .eslintignore and it works fine. If you want linting in the .eslint.js, if you add .eslint.js in the include, it will probably work

@clehene
Copy link

clehene commented May 27, 2020

@gSarciotto thank you! We ended up ignoring it but would like now to configure it so that .eslintrc.js would still get the regular linting. I'm guessing that, since typescript-eslint doesn't discriminate by file type, it could be handled through the general eslint config with an overrides config, but haven't got a chance to look at that.

@sigmaprojects
Copy link

I still have this problem every time I create a new file. VSCode complains until it restarts.

@bradzacher
Copy link
Member

bradzacher commented Jun 21, 2020

need significantly more information than that to be able to help you.
help me to help you.

please file a new issue.

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Jun 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

No branches or pull requests

10 participants