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.

Parsing fails on scriptless Vue files with typescript-eslint parser

See original GitHub issue

When using an eslint config that specifies parserOptions.parser.ts, eslint errors while parsing files that do not have at least an empty <script lang="ts"></script>.

The eslint error is:

Error: Error while loading rule '@typescript-eslint/await-thenable': 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 /src/error.vue
    at Object.getParserServices (/node_modules/@typescript-eslint/experimental-utils/dist/eslint-utils/getParserServices.js:16:15)
    at create (/node_modules/@typescript-eslint/eslint-plugin/dist/rules/await-thenable.js:41:37)
    at Object.create (/node_modules/@typescript-eslint/experimental-utils/dist/eslint-utils/RuleCreator.js:13:24)
    at createRuleListeners (/node_modules/eslint/lib/linter/linter.js:761:21)
    at /node_modules/eslint/lib/linter/linter.js:931:31
    at Array.forEach (<anonymous>)
    at runRules (/node_modules/eslint/lib/linter/linter.js:876:34)
    at Linter._verifyWithoutProcessors (/node_modules/eslint/lib/linter/linter.js:1175:31)
    at Linter._verifyWithConfigArray (/node_modules/eslint/lib/linter/linter.js:1273:21)
    at Linter.verify (/node_modules/eslint/lib/linter/linter.js:1228:25)

Config:

module.exports = {
    env: {
        es6: true,
        browser: true,
        node: true,
    },
    overrides: [
        {
            files: [
                '*.vue',
            ],
            plugins: [
                'vue', // With or without this, the error occurs
                '@typescript-eslint',
            ],
            parser: 'vue-eslint-parser',
            parserOptions: {
                parser: {
                    '<template>': 'espree',
                    ts: '@typescript-eslint/parser',
                },
                project: ['./tsconfig.json'],
                extraFileExtensions: ['.vue'],
            },
            rules: {
                '@typescript-eslint/await-thenable': 'error',
            },
        },
    ],
}

Reproduction: https://github.com/MatthiasKunnen/eslint-plugin-vue-ts-script.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
LinusBorgcommented, Sep 6, 2021

When you say “the same error”, are you referring to the error about the typescript-eslint rule?

That would be expected. A JS parser like spree can’t provide type informaiton to a type-aware rule. Using typescript-eslint - at the very least when using type-aware rules - will always require the typescript-eslint parser to be set.

0reactions
MatthiasKunnencommented, Sep 6, 2021

A JS parser like spree can’t provide type informaiton to a type-aware rule.

I’m well aware. I was just remarking that a .vue file without <script> is currently parsed with a JS/TS parser while it would not need to be. While this is not a problem for me as I set js: '@typescript-eslint/parser', it might catch people off-guard as they could expect a file without script to not perform script parsing. Now I understand that due to ESLint limitations, selecting a JS/TS parser could be required. However, documenting the need for js: '@typescript-eslint/parser' would be beneficial for users that make the same assumption I did.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue3, Typescript and Eslint raise: "Parsing error: '}' expected"
The error is caused by "plugin:@typescript-eslint/recommended" , which sets the top-level parser , which collides with Vue's ...
Read more >
error while loading rule '@typescript-eslint/await-thenable'
When using an eslint config that specifies parserOptions.parser.ts , eslint errors while parsing files that do not have at least an empty <script...
Read more >
@typescript-eslint/parser - npm
Start using @typescript-eslint/parser in your project by running `npm i ... .js , .jsx , .tsx files are parsed as if this is...
Read more >
General Advice on Setup & Resolving Issues - SonarCloud
When the former fails, the later takes over. Speaking from experience, typescript-eslint parser fails to parse a file without syntactic ...
Read more >
解析失败了具有类型签名- eslint解析器的脚本vue文件
Parsing fails on scriptless Vue files with typescript-eslint parserWhen using an eslint config that specifies parserOptions.parser.ts ...
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