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

Bug: Error while loading rule '@typescript-eslint/consistent-type-imports': You have used a rule which requires parserServices to be generated #8777

Closed
4 tasks done
gimi-anders opened this issue Mar 26, 2024 · 8 comments
Labels
triage Waiting for maintainers to take a look

Comments

@gimi-anders
Copy link

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Relevant Package

typescript-eslint

Playground Link

No response

Repro Code

overrides: [
    {
      files: ["*.js", "*.jsx"],
      parser: "@babel/eslint-parser",
      parserOptions: {
        project: "./jsconfig.json",
      },
    },
  ]

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: "./tsconfig.json",
  },
  overrides: [
    {
      files: ["*.js", "*.jsx"],
      parser: "@babel/eslint-parser",
      parserOptions: {
        project: "./jsconfig.json",
      },
    },
  ]
};

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

I expected to be able to run lint successfully.

Actual Result

I was not able to run lint. I got this error message:

Error: Error while loading rule '@typescript-eslint/consistent-type-imports': 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.
Parser: [path-to-project]/node_modules/@babel/eslint-parser/lib/index.cjs
Note: detected a parser other than @typescript-eslint/parser. Make sure the parser is configured to forward "parserOptions.project" to @typescript-eslint/parser.
Occurred while linting [path-to-project]/.eslintrc.js

Additional Info

I have configured eslint to use different parser for js and ts files. This causes issue with version 7.4.0 of @typescript-eslint/parser.

Note that everything works fine with version 7.3.1.

Versions

package version
@typescript-eslint/eslint-plugin 7.4.0
@typescript-eslint/parser 7.4.0
TypeScript 5.4.3
ESLint 8.57.0
@gimi-anders gimi-anders added bug Something isn't working triage Waiting for maintainers to take a look labels Mar 26, 2024
@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Mar 26, 2024

Parser: [path-to-project]/node_modules/@babel/eslint-parser/lib/index.cjs

We don't (and can't reasonably) support @babel/eslint-parser. It generates a shape different from what our tooling expects.

Playground Link
No response

Looks like you used the wrong issue template 🙂. We'll need a full reproduction to be able to help. This issue doesn't have your package.json, lockfile, etc. Could you please post a way for me, an internet stranger, to reproduce what you're seeing?

If there was a change in our handling of unsupported parsers between versions, we'd want to investigate. But without a real reproduction we can't.

Oh, and:

@JoshuaKGoldberg JoshuaKGoldberg added awaiting response Issues waiting for a reply from the OP or another party unable to repro issues that a maintainer was not able to reproduce and removed triage Waiting for maintainers to take a look labels Mar 26, 2024
@gimi-anders
Copy link
Author

@JoshuaKGoldberg Sorry for using wrong template, I was unsure which one to use.

There are no good reasons we are using @babel/eslint-parser. Our eslint config hasn't been updated for a long time, so it is just how it was configured back in time.
What parsers would you recommend, or how do you recommend us to configure eslint when we have both *.js and *.ts files in our project?

Sorry for not providing our package.json or lockfile, I will attach it here.

package.json

@JoshuaKGoldberg
Copy link
Member

Super thanks!

I'd recommend removing the @babel/eslint-parser entry and always using @typescript-eslint/parser. It supports both JS and TS code. If that doesn't work for you, our community Discord has a #help channel you can ask for more detailed help on.

I filed typescript-eslint/typescript-eslint-examples#10 to track adding more concrete examples showing this.

@JoshuaKGoldberg JoshuaKGoldberg closed this as not planned Won't fix, can't repro, duplicate, stale Mar 26, 2024
@JoshuaKGoldberg JoshuaKGoldberg added question Questions! (i.e. not a bug / enhancment / documentation) external This issue is with another package, not typescript-eslint itself and removed bug Something isn't working awaiting response Issues waiting for a reply from the OP or another party external This issue is with another package, not typescript-eslint itself unable to repro issues that a maintainer was not able to reproduce labels Mar 26, 2024
@bradzacher
Copy link
Member

bradzacher commented Mar 26, 2024

I would also recommend checking out our getting started guide for steps to setup your codebase:
https://typescript-eslint.io/getting-started/

@frankykubo
Copy link

I have same problem using @typescript-eslint/parser on vue project.

@JoshuaKGoldberg
Copy link
Member

repro pls

@frankykubo
Copy link

frankykubo commented Mar 27, 2024

I noticed that if I use "@vue/eslint-config-typescript": "^12.0.0",, i dont get such error. If I update it to "@vue/eslint-config-typescript": "^13.0.0",, this error shows up.

Here is my .eslintrc.cjs:

/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution');

module.exports = {
  root: true,
  extends: [
    'plugin:cypress/recommended',
    'plugin:vue/vue3-recommended',
    '@vue/typescript/recommended',
    'eslint:recommended',
    'plugin:import/errors',
    'plugin:import/warnings',
    'plugin:import/typescript',
  ],
  parserOptions: {
    ecmaVersion: 'latest',
  },
  ignorePatterns: 'cypress/*',
  env: {
    browser: true,
    node: true,
    es2021: true,
  },
  plugins: ['vue', 'cypress', 'import', 'import-newlines'],
  settings: {
    'import/resolver': {
      typescript: {}, // This will use <root>/tsconfig.json by default
      node: {
        extensions: ['.js', '.ts', '.vue'],
      },
    },
  },
  rules: {
    'array-bracket-spacing': [2, 'never'],
    'arrow-spacing': [2, {
      'before': true,
      'after': true,
    }],
    'block-spacing': [2, 'always'],
    'brace-style': [2, '1tbs'],
    'camelcase': [0, {
      'properties': 'always',
    }],
    'comma-dangle': ['error', 'always-multiline'],
    'comma-spacing': [2, {
      'before': false,
      'after': true,
    }],
    'comma-style': [2, 'last'],
    'curly': [2, 'all'],
    'dot-location': [2, 'property'],
    'eol-last': 2,
    'eqeqeq': ['error', 'always', { 'null': 'ignore' }],
    'handle-callback-err': [2, '^(err|error)$'],
    'indent': [2, 2, {
      'SwitchCase': 1,
    }],
    'allowIndentationTabs': 'off',
    'jsx-quotes': [2, 'prefer-single'],
    'key-spacing': [2, {
      'beforeColon': false,
      'afterColon': true,
    }],
    'keyword-spacing': [2, {
      'before': true,
      'after': true,
    }],
    'new-cap': [2, {
      'newIsCap': true,
      'capIsNew': false,
    }],
    'new-parens': 2,
    'no-array-constructor': 2,
    'no-async-promise-executor': 'off',
    'no-caller': 2,
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-eval': 2,
    'no-extend-native': 2,
    'no-extra-parens': [2, 'functions'],
    'no-floating-decimal': 2,
    'no-implied-eval': 2,
    'no-inner-declarations': [2, 'functions'],
    'no-iterator': 2,
    'no-label-var': 2,
    'no-labels': [2, {
      'allowLoop': false,
      'allowSwitch': false,
    }],
    'no-lone-blocks': 2,
    'no-multi-spaces': 2,
    'no-multiple-empty-lines': [2, {
      'max': 1,
    }],
    'no-native-reassign': 2,
    'no-negated-in-lhs': 2,
    'no-new-object': 2,
    'no-new-require': 2,
    'no-new-wrappers': 2,
    'no-octal-escape': 2,
    'no-path-concat': 2,
    'no-proto': 2,
    'no-return-assign': [2, 'except-parens'],
    'no-self-compare': 2,
    'no-sequences': 2,
    'no-spaced-func': 2,
    'no-throw-literal': 2,
    'no-trailing-spaces': 2,
    'no-undef-init': 2,
    'no-unmodified-loop-condition': 2,
    'no-unneeded-ternary': [2, {
      'defaultAssignment': false,
    }],
    'no-unused-vars': 'off',
    'no-useless-call': 2,
    'no-useless-escape': 0,
    'no-useless-computed-key': 2,
    'no-useless-constructor': 2,
    'no-whitespace-before-property': 2,
    'object-curly-spacing': [2, 'always', {
      objectsInObjects: false,
    }],
    'operator-linebreak': [2, 'after', {
      'overrides': {
        '?': 'before',
        ':': 'before',
      },
    }],
    'padded-blocks': [2, 'never'],
    'quotes': [2, 'single', {
      'avoidEscape': true,
      'allowTemplateLiterals': true,
    }],
    'semi': ['error', 'always'],
    'semi-spacing': [2, {
      'before': false,
      'after': true,
    }],
    'space-before-function-paren': [2, 'never'],
    'space-in-parens': [2, 'never'],
    'space-infix-ops': 2,
    'space-unary-ops': [2, {
      'words': true,
      'nonwords': false,
    }],
    'spaced-comment': [2, 'always', {
      'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ','],
    }],
    'template-curly-spacing': [2, 'never'],
    'wrap-iife': [2, 'any'],
    'yield-star-spacing': [2, 'both'],
    'yoda': [2, 'never'],
    'prefer-const': 2,
    'vue/max-attributes-per-line': [2, {
      'singleline': 10,
      'multiline': 1,
    }],
    'vue/name-property-casing': ['off', 'PascalCase' | 'kebab-case'],
    'vue/no-v-html': 'off',
    'vue/no-multiple-template-root': 'off',
    'vue/no-v-for-template-key': 'off',
    'vue/multiline-html-element-content-newline': 'off',
    'vue/singleline-html-element-content-newline': 'off',
    'vue/multi-word-component-names': 'off',
    'vue/v-on-event-hyphenation': 'off',
    '@typescript-eslint/no-explicit-any': 'off',
    '@typescript-eslint/ban-ts-comment': 'off',
    '@typescript-eslint/consistent-type-imports': [
      'error',
      {
        'prefer': 'type-imports',
        'disallowTypeAnnotations': false,
      },
    ],
    '@typescript-eslint/no-non-null-assertion': 'off',
    'vue/no-setup-props-destructure': 'off',
    // Your existing rules...
    'import/order': ['error', {
      'groups': [
        'builtin',
        'external',
        'internal',
        'parent',
        'sibling',
        'index',
        'object',
        'type',
      ],
      'pathGroups': [
        {
          'pattern': '@/**/*',
          'group': 'internal',
        },
        {
          'pattern': './**/*',
          'group': 'internal',
        },
      ],
      'newlines-between': 'never',
      'alphabetize': {
        'order': 'asc',
        'caseInsensitive': true,
      },
    }],
    'import/first': 'error',
    'import/no-duplicates': 'error',
    'import/no-unresolved': 'error',
    // 'object-curly-newline': ['error', {
    //   'ImportDeclaration': 'never',
    // }],
    'import-newlines/enforce': ['error', { items: 40, 'max-len': 200 }],
  },
};

@JoshuaKGoldberg JoshuaKGoldberg added triage Waiting for maintainers to take a look and removed question Questions! (i.e. not a bug / enhancment / documentation) labels Mar 27, 2024
@bradzacher
Copy link
Member

bradzacher commented Mar 27, 2024

@frankykubo I'm going to go ahead and say to file a new issue.
Your issue is unrelated to this one.

The same error message but clearly a different cause given that OP encountered this due to the babel parser and you're using the Vue parser.

Please file a new issue using the 🐛 Complex Bug With a Reproduction template and provide us with a repro repo with the required dependencies and reproduction steps.

Additionally we ask for a MINIMAL reproduction - just the minimum config and deps to reproduce the error. That config is quite far from minimal!

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
triage Waiting for maintainers to take a look
Projects
None yet
Development

No branches or pull requests

4 participants