Skip to content

Error resolving peer plugins when using pnpm v10 #470

@waspeer

Description

@waspeer

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.

What version of ESLint are you using?

9.21.0

What version of eslint-plugin-astro are you using?

1.3.1

What did you do?

I ran into this issue when trying to install my shareable config. eslint-plugin-jsx-a11y and @typescript-eslint/parser were both not found. This issue was encountered when using the eslint vscode extension and installing the config with pnpm v10. To be precise:

  • ERROR: in vscode extension + pnpm v10
  • SUCCESS: in vscode extension + npm v11
  • SUCCESS: running pnpm exec eslint + pnpm v10

Seems to be related to pnpm/pnpm#8378

VSCode version: 1.97.2
ESLint extension version: 3.0.10

JSX A11y

The error:

ConfigError: Config (unnamed): Key "plugins": Key "jsx-a11y": Expected an object.

After inspection it seemed getPluginJsxA11y had returned null. I fixed this by changing my shareable config to this:

import ts from 'typescript-eslint';
import astro from 'eslint-plugin-astro';
import jsxA11y from 'eslint-plugin-jsx-a11y';

export const baseConfig = ts.config(
  // ...
  {
    ...jsxA11y.flatConfigs.recommended,
    files: ['**/*.{jsx,tsx,astro}'],
  },
  ...astro.configs['flat/jsx-a11y-recommended'].map(
    (config) => delete config?.plugins?.['jsx-a11y'] && config,
  ),
);

Typescript-ESLint parser

After that I got this error:

Error: Error while loading rule '@typescript-eslint/consistent-type-imports': You have used a rule which requires type information, but don't have parserOptions set to generate type information for this file. See https://typescript-eslint.io/getting-started/typed-linting for enabling linting with type information.
Parser: astro-eslint-parser
Note: detected a parser other than @typescript-eslint/parser. Make sure the parser is configured to forward "parserOptions.project" to @typescript-eslint/parser.

This seemed to be caused by src/configs/has-typescript-eslint-parser.ts not finding @typescript-eslint/parser. I fixed this by changing my shareable config to:

import ts from 'typescript-eslint';
import astro from 'eslint-plugin-astro';
import tsParser from '@typescript-eslint/parser';

export const baseConfig = ts.config(
  // ...
  ...astro.configs['flat/recommended'].map((config) =>
    config?.languageOptions?.parserOptions && 'parser' in config.languageOptions.parserOptions
      ? {
          ...config,
          languageOptions: {
            ...config.languageOptions,
            parserOptions: {
              ...config.languageOptions.parserOptions,
              parser: tsParser,
            },
          },
        }
      : config,
  )
);

It might also be useful to note that this worked as well:

import { createRequire } from 'node:module';

const tsParser = createRequire(import.meta.url)('@typescript-eslint/parser');

// ...
Configuration
// Consumer
import { configs } from "@waspeer/config/eslint";
export default configs.base;

// Shareable config
import astro from 'eslint-plugin-astro';
import ts from 'typescript-eslint';

export const baseConfig = ts.config(
  // ...
  // Astro
  ...astro.configs['flat/recommended'],
  ...astro.configs['flat/jsx-a11y-recommended'],
);

What did you expect to happen?

See above

What actually happened?

See above

Link to Minimal Reproducible Example

https://github.com/waspeer/eslint-plugin-astro-pnpm-10

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions