question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`@typescript-eslint/eslint-plugin` crashes when applying rules to Vue SFC `<script>` not parsed with `@typescript-eslint/parser`

See original GitHub issue

While using @typescript-eslint/recommended-requiring-type-checking with vue-eslint-parser as parser, @typescript-eslint/parser can’t check for types when there is no <script> used in a Vue SFC.

Stacktrace:

Oops! Something went wrong! :(

ESLint: 8.17.0

Error: Error while loading rule '@typescript-eslint/dot-notation': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
Occurred while linting /Users/drjume/Desktop/falconDev/my-falcondev/apps/web/src/views/NotFoundView.vue
    at getParserServices (/Users/drjume/Desktop/falconDev/my-falcondev/node_modules/.pnpm/@typescript-eslint+utils@5.27.1_ud6rd4xtew5bv4yhvkvu24pzm4/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:16:15)
    at create (/Users/drjume/Desktop/falconDev/my-falcondev/node_modules/.pnpm/@typescript-eslint+eslint-plugin@5.27.1_aq7uryhocdbvbqum33pitcm3y4/node_modules/@typescript-eslint/eslint-plugin/dist/rules/dot-notation.js:85:81)
    at Object.create (/Users/drjume/Desktop/falconDev/my-falcondev/node_modules/.pnpm/@typescript-eslint+utils@5.27.1_ud6rd4xtew5bv4yhvkvu24pzm4/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:42:20)
    at createRuleListeners (/Users/drjume/Desktop/falconDev/my-falcondev/node_modules/.pnpm/eslint@8.17.0/node_modules/eslint/lib/linter/linter.js:922:21)
    at /Users/drjume/Desktop/falconDev/my-falcondev/node_modules/.pnpm/eslint@8.17.0/node_modules/eslint/lib/linter/linter.js:1104:31
    at Array.forEach (<anonymous>)
    at runRules (/Users/drjume/Desktop/falconDev/my-falcondev/node_modules/.pnpm/eslint@8.17.0/node_modules/eslint/lib/linter/linter.js:1041:34)
    at Linter._verifyWithoutProcessors (/Users/drjume/Desktop/falconDev/my-falcondev/node_modules/.pnpm/eslint@8.17.0/node_modules/eslint/lib/linter/linter.js:1389:31)
    at /Users/drjume/Desktop/falconDev/my-falcondev/node_modules/.pnpm/eslint@8.17.0/node_modules/eslint/lib/linter/linter.js:1798:29
    at Array.map (<anonymous>)

When adding an empty <script setup lang="ts"></script> the error is not shown anymore when running eslint.

The issue seems to be, that the parserServices or a property of it is missing when there is no <script> in a Vue SFC:

https://github.com/typescript-eslint/typescript-eslint/blob/dc1f9309cf04aa7314e758980ac687558482f47f/packages/utils/src/eslint-utils/getParserServices.ts#L19-L26

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ota-meshicommented, Jun 23, 2022

Thank you for posting issue.

Would something like this be possible?:

I think it’s technically impossible. TypeScript cannot provide type information for virtual filenames. This means that if we assign a virtual file name, you will not be able to use “recommended-requiring-type-checking”.

0reactions
freakzlikecommented, Aug 11, 2022

I fixed my error by setting the parserOptions.parser inside the .eslintrc.js:

parserOptions: {
  parser: '@typescript-eslint/parser'
},
Read more comments on GitHub >

github_iconTop Results From Across the Web

`@typescript-eslint/eslint-plugin` crashes when applying rules ...
`@typescript-eslint/eslint-plugin` crashes when applying rules to Vue SFC `<script>` not parsed with `@typescript-eslint/parser`.
Read more >
False positives when using with Vue SFC · Issue #883 - GitHub
Since the analysis by @typescript-eslint/parser fails, the vue file is reported as a parsing error.
Read more >
@typescript-eslint/eslint-plugin | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Add ESLint to a Meteor + Vue + Typescript project
I can get it successfully parsing and formatting Typescript files but it is throwing syntax errors for the .vue files. ESLint related ...
Read more >
General Advice on Setup & Resolving Issues - SonarCloud
Yes we do use Vue.JS SFC. Those files do have some of those. ... Speaking from experience, typescript-eslint parser fails to parse a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found