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 Vue SFC File: Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser #1303

Closed
eyedean opened this issue Dec 4, 2019 · 20 comments · Fixed by #1424
Assignees
Labels
bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree triage Waiting for maintainers to take a look

Comments

@eyedean
Copy link

eyedean commented Dec 4, 2019

What code were you trying to parse?
I run into the infamous error of not finding the parser (similar to #1159 and #883) for new Vue files I create in my project. NOTE: a restart of VS and my live compiler eliminates the problem until the next time I create a new .vue file.

I am using Quasar, and vue-class-component for my SFC Vue files.

Error details:

 error  in ./src/components/signup/CLSignupStepperHeader.vue

Module Error (from ./node_modules/eslint-loader/index.js):

/Users/eyedean/dev/xxxxx/src/components/signup/CLSignupStepperHeader.vue
  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: src/components/signup/CLSignupStepperHeader.vue.
The file must be included in at least one of the projects provided

✖ 1 problem (1 error, 0 warnings)


 @ ./node_modules/ts-loader??ref--10-0!./node_modules/vue-loader/lib??vue-loader-options!./src/pages/signup/CLSignupStepVitals.vue?vue&type=script&lang=ts& 10:0-81 143:12-33

Per the request at #1159 (comment) I am creating this new ticket.

What did you expect to happen?
The new Vue file should be picked up normally. Again, a restart of live tsc and VS code fixes it, but it kinda takes 1 minute for my project.

What actually happened?
It used to work flawlessly until I upgraded typescript-eslint, after a few months, recently. Looking at e3f3448 which was the fix for a similar problem, the symptom I am seeing is very related to parsedFilesSeen not picking up the newly created file .vue on-the-fly.

Additional Notes
Per https://eslint.vuejs.org/user-guide/#how-to-use-custom-parser for parsing Vue files, I have the following in my .eslintrc:

	parser: "vue-eslint-parser",
	
	// Must use parserOptions instead of "parser" to allow vue-eslint-parser to keep working
	// See https://eslint.vuejs.org/user-guide/#how-to-use-custom-parser
	// `parser: "vue-eslint-parser"` is already included with any "plugin:vue/**" config and should be omitted
	parserOptions: {
		project: "./tsconfig.eslint.json",
		parser: "@typescript-eslint/parser",
		sourceType: "module",
		extraFileExtensions: [".vue"]
	},

And then it is in my tsconfig.eslint.json that I am mentioning all the Vue files should be picked:

{
	"extends": "./tsconfig.json",
	"include": [
	  "**/*.ts",
	  "**/*.js",
	  "**/*.vue",
	  "**/*.json",
	],
	"compilerOptions": {
	  "allowJs": true,
	  "checkJs": true
	}
}

Versions

package version
@typescript-eslint/parser 2.10.0 (was the same on 2.8.0)
TypeScript 3.3.3
ESLint 5.16.0 (It's on purpose to be on 5, rather than 6)
node 12.3.1
npm 6.13.0
@eyedean eyedean added package: parser Issues related to @typescript-eslint/parser triage Waiting for maintainers to take a look labels Dec 4, 2019
@bradzacher bradzacher added bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree and removed package: parser Issues related to @typescript-eslint/parser labels Dec 4, 2019
@yoyo930021
Copy link
Contributor

yoyo930021 commented Dec 13, 2019

If you try to upgrade TypeScript ?
I cann't reproduce.

Talk your @typescript-eslint/typescript-estree version ?

@eyedean
Copy link
Author

eyedean commented Dec 18, 2019

@yoyo930021
It's version": "2.10.0"

PS. Also, my Typescript is 3.7.3 now and the same is still happening.

@demisx
Copy link

demisx commented Dec 26, 2019

This also happens to me too in VS Code when a new file is added. Have to restart VS Code each time for it to go away.

  • typescript@3.5.3
  • @typescript-eslint/parser@2.13.0
  • @typescript-eslint/typescript-estree@2.13.0

@armano2
Copy link
Member

armano2 commented Jan 8, 2020

@eyedean @demisx @yoyo930021 today we merged pr (#1412) that fixes ~similar issue (not in vue sfc), can you re-test it with 2.15.1-alpha.5 or provide step by step example how to reproduce it?

@armano2 armano2 self-assigned this Jan 8, 2020
@robbiespeed
Copy link

@armano2 I tested typescript-estree version 2.15.1-alpha.7 and it still has the issue with newly created ts/tsx files when using the vscode extension

@armano2
Copy link
Member

armano2 commented Jan 9, 2020

@robbiespeed can you tell me step by step what are you doing (files/folders wise), or is this happening for any .vue file? what OS are you using? and which version of vue-eslint-parser you are using?

@eyedean
Copy link
Author

eyedean commented Jan 10, 2020

Thanks for looking into this @armano2 .

I just tested 2.15.1-alpha-7 parser, and I still have the problem. It's even happening on my Node.js repo (only .ts files), so shouldn't be Vue or SFC specific.

All I do is I duplicate one of the files I have (basically create a new file with some .ts content) and it errors on the first character of the first line with the same parsing error as above.
Screenshot at Jan 09 16-02-48

It goes away when I restart my VS Code (cmd+shift+P, Reload Window). I am on Mac OS 10.14.5 and VS Code 1.41.1. I have this issue constantly since like a month ago and I didn't have this issue like 3 months ago.

My feeling is for some reason the eslint service in the background (both for VS code and my Quasar CLI front-end compiler) doesn't recognize the new files when they are created while the service is up. But after a restart, when it does a full new scan, it's fine with the file being already there.

@armano2
Copy link
Member

armano2 commented Jan 10, 2020

i was able to reproduce this in simple example project, i will take a look into this

@eyedean
Copy link
Author

eyedean commented Jan 10, 2020

Also, since it's only happening to some of us, I wonder if it might be something in the config that we are doing wrong.

(Screenshot removed for personal security concerns)

@armano2
Copy link
Member

armano2 commented Jan 10, 2020

this is completly unrelated to rules or vue plugin

image

if someone is interested repo: https://github.com/armano2/typescript-eslint-1394

@robbiespeed
Copy link

robbiespeed commented Jan 10, 2020

It seems to only happen randomly now when creating a file in a newly created folder.

Here's one of the errors with debug enabled:

2020-01-10T00:24:36.722Z eslint:ignore-pattern Check {
  filePath: '/home/rspeed/Projects/tern/src/web/components/flkjajflkafsjl/index.tsx',
  dot: false,
  relativePath: 'src/web/components/flkjajflkafsjl/index.tsx',
  result: false
}
2020-01-10T00:24:36.722Z eslint:cascading-config-array-factory Load config files for /home/rspeed/Projects/tern/src/web/components/flkjajflkafsjl.
2020-01-10T00:24:36.722Z eslint:cascading-config-array-factory Cache hit: /home/rspeed/Projects/tern/src/web/components/flkjajflkafsjl.
2020-01-10T00:24:36.722Z eslint:cli-engine Lint /home/rspeed/Projects/tern/src/web/components/flkjajflkafsjl/index.tsx
2020-01-10T00:24:36.722Z eslint:linter Linting code for /home/rspeed/Projects/tern/src/web/components/flkjajflkafsjl/index.tsx (pass 1)
2020-01-10T00:24:36.722Z eslint:linter Verify
2020-01-10T00:24:36.722Z eslint:linter With ConfigArray: /home/rspeed/Projects/tern/src/web/components/flkjajflkafsjl/index.tsx
2020-01-10T00:24:36.792Z eslint:linter Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: src/web/components/flkjajflkafsjl/index.tsx.
The file must be included in at least one of the projects provided.
Error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: src/web/components/flkjajflkafsjl/index.tsx.
The file must be included in at least one of the projects provided.
    at Object.createProjectProgram (/home/rspeed/Projects/tern/node_modules/@typescript-eslint/typescript-estree/dist/create-program/createProjectProgram.js:58:15)
    at getProgramAndAST (/home/rspeed/Projects/tern/node_modules/@typescript-eslint/typescript-estree/dist/parser.js:60:32)
    at Object.parseAndGenerateServices (/home/rspeed/Projects/tern/node_modules/@typescript-eslint/typescript-estree/dist/parser.js:294:30)
    at Object.parseForESLint (/home/rspeed/Projects/tern/node_modules/@typescript-eslint/parser/dist/parser.js:53:51)
    at parse (/home/rspeed/Projects/tern/node_modules/eslint/lib/linter/linter.js:640:22)
    at Linter._verifyWithoutProcessors (/home/rspeed/Projects/tern/node_modules/eslint/lib/linter/linter.js:1111:33)
    at Linter._verifyWithConfigArray (/home/rspeed/Projects/tern/node_modules/eslint/lib/linter/linter.js:1255:21)
    at Linter.verify (/home/rspeed/Projects/tern/node_modules/eslint/lib/linter/linter.js:1210:25)
    at Linter.verifyAndFix (/home/rspeed/Projects/tern/node_modules/eslint/lib/linter/linter.js:1400:29)
    at verifyText (/home/rspeed/Projects/tern/node_modules/eslint/lib/cli-engine/cli-engine.js:230:48)
2020-01-10T00:24:36.792Z eslint:linter Generating fixed text for /home/rspeed/Projects/tern/src/web/components/flkjajflkafsjl/index.tsx (pass 1)
System / Project Details

os: Linux (Fedora 30)

vscode: 1.14.0

eslint extension: microsoft/eslint 2.0.13

eslint: 6.7.2

typescript-eslint/eslint-plugin: 2.15.0

typescript-eslint/parser: 2.15.0

typescript-eslint/typescript-estree: 2.15.1-alpha.7

tsconfig.json:

{
  "compilerOptions": {
    "noEmit": true,
    "lib": [
      "ES2020",
      "DOM"
    ],
    "target": "ES2019",
    "module": "commonjs",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowJs": false,
    "jsx": "preserve",
    "jsxFactory": "createElement",
    "experimentalDecorators": true,
    "strictNullChecks": true,
    "noUnusedLocals": true,
    "strict": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "suppressImplicitAnyIndexErrors": true,
  }
}

(Also tried adding "include": "./**/*")

.eslintrc.json:

{
  "env": {
    "browser": true,
    "es6": true,
    "node": true
  },
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.json",
    "sourceType": "module"
  },
  "plugins": [
    "@typescript-eslint"
  ],
  "ignorePatterns": [
    "/.nyc_output",
    "/build",
    "/coverage",
    "/node_modules"
  ],
  "rules": {
    "@typescript-eslint/class-name-casing": "error",
    "@typescript-eslint/indent": ["error", 2, {
      "SwitchCase": 1,
      // to work around bugs, see https://github.com/typescript-eslint/typescript-eslint/milestone/1
      "ignoredNodes": [
        "CallExpression[typeParameters]",
        "TSTypeParameterInstantiation",
        "TSTypeAnnotation > TSParenthesizedType",
        "TSFunctionType > TSTypeAnnotation"
      ]
    }],
    "@typescript-eslint/member-delimiter-style": [
      "error",
      {
        "multiline": {
          "delimiter": "semi",
          "requireLast": true
        },
        "singleline": {
          "delimiter": "semi",
          "requireLast": false
        }
      }
    ],
    "@typescript-eslint/no-for-in-array": "error",
    "@typescript-eslint/no-require-imports": "error",
    "@typescript-eslint/prefer-for-of": "error",
    "@typescript-eslint/prefer-namespace-keyword": "error",
    "@typescript-eslint/quotes": [
      "error",
      "single",
      {
        "allowTemplateLiterals": true
      }
    ],
    "@typescript-eslint/semi": [
      "error",
      "always"
    ],
    "@typescript-eslint/space-before-function-paren": ["error"],
    "@typescript-eslint/type-annotation-spacing": "error",
    "arrow-parens": [
      "error",
      "always"
    ],
    "brace-style": [
      "error",
      "stroustrup"
    ],
    "camelcase": "error",
    "curly": "error",
    "eqeqeq": [
      "error",
      "smart"
    ],
    "id-blacklist": "off",
    "id-match": "off",
    // disabled in favour of @typescript-eslint/indent
    "indent": "off",
    "keyword-spacing": "error",
    "max-len": [
      "error",
      {
        "code": 100
      }
    ],
    "new-parens": "error",
    "no-eval": "error",
    "no-redeclare": "error",
    "no-trailing-spaces": "error",
    "no-unsafe-finally": "error",
    "no-var": "error",
    "object-curly-spacing": ["error", "always"],
    "prefer-const": "error",
    // disabled in favour of @typescript-eslint/quotes
    "quotes": "off",
    "semi-spacing": ["error", {"before": false, "after": true}],
    "space-before-blocks": "error",
    // disabled in favour of @typescript-eslint/space-before-function-paren
    "space-before-function-paren": "off",
    "space-in-parens":"error",
    "space-infix-ops": ["error", { "int32Hint": false }],
    "spaced-comment": "error"
  }
}

@armano2
Copy link
Member

armano2 commented Jan 11, 2020

Small update about my research:

  • this is not vue specific issue (its present for any custom extension)
  • this issue can be reproduced only within vscode (its working correctly in other editors that i tested)
  • root cause: for some reason typescript adds to many folders into watch (./src and ./) and that causes our validation to fail
  • i'm unable to reproduce this within unit tests,
  • This issue seems to be related to what vscode or vscode-eslint does to typescript (code base of those projects is to big for me to find where and why)
  • I opened ticket about this in vscode-eslint -> maybe they will be able to help me understand whats going on there eslint parserOption.project issue with typescript-eslint microsoft/vscode-eslint#872
  • On our side there is way to patch this issue by marking registered directories recursively that match specified path 967114b but i'm unable to test this outisde vscode
  • while working on this ticket i discovered one more issue with persisted parse, relative paths was not correctly watched fix(typescript-estree): fix persisted parse for relative paths #1424

@robbiespeed
Copy link

this is not vue specific issue (its present for any custom extension)

What is meant by custom extension?
It's happening with .ts and .tsx files as well, but I haven't found the steps that reproduce it consistently.

@armano2
Copy link
Member

armano2 commented Jan 12, 2020

custom -> not supported natively by typescript (ts, tsx, js, jsx, json)

in vscode settings i changed file association of *.test to typescript and added it to project configs,
with that i was having same issue and this rules out potential issue with vue-eslint-parser.

// edit: i hate typing on phone

@armano2
Copy link
Member

armano2 commented Jan 12, 2020

It's happening with .ts and .tsx files as well, but I haven't found the steps that reproduce it consistently.

as for ts and tsx files: vscode is starting failing on all files after first custom (eg. vue) file is created

@robbiespeed
Copy link

@armano2 I have only tsx and ts files in my project and it's still happening. I'll try and create an example project to reproduce.

@cgwic
Copy link

cgwic commented Jan 12, 2020

My temporary solution: additional tsconfigs for files with errors. In my case one tsconfig for every problem directory.

@eyedean
Copy link
Author

eyedean commented Jan 13, 2020

Thanks for working on this @armano2 and @bradzacher. Please let me know when it's going to be out, so I can verify and confirm that the fix is working for both my .ts and .vue projects. Thanks! 🙌

@armano2
Copy link
Member

armano2 commented Jan 13, 2020

it should be live already you can check alpha version 2.15.1-alpha.16

@eyedean
Copy link
Author

eyedean commented Jan 13, 2020

Magic! 🎉 I confirm that it's now fixed for both .ts and .vue files in 2.15.1-alpha.16. Thanks a lot, @armano2 !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree triage Waiting for maintainers to take a look
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants