antfu / eslint-config

Anthony's ESLint config preset
https://eslint-config.antfu.me/
MIT License
3.41k stars 400 forks source link

[Nuxt] Error: Key "plugins": Cannot redefine plugin "import". #473

Closed onmax closed 1 month ago

onmax commented 1 month ago

Describe the bug

Running eslint results in an error. I tried to follow the manual but got this error:

Error

```bash maxi@maxi:~/personal/eslint-reproduction-bug$ nr lint:fix > nuxt-app@ lint:fix /home/maxi/personal/eslint-reproduction-bug > eslint . --fix Oops! Something went wrong! :( ESLint: 9.2.0 ConfigError: Config "antfu/imports/rules": Key "plugins": Cannot redefine plugin "import". at rethrowConfigError (/home/maxi/personal/eslint-reproduction-bug/node_modules/.pnpm/@humanwhocodes+config-array@0.13.0/node_modules/@humanwhocodes/config-array/api.js:230:8) at /home/maxi/personal/eslint-reproduction-bug/node_modules/.pnpm/@humanwhocodes+config-array@0.13.0/node_modules/@humanwhocodes/config-array/api.js:1032:5 at Array.reduce () at FlatConfigArray.getConfig (/home/maxi/personal/eslint-reproduction-bug/node_modules/.pnpm/@humanwhocodes+config-array@0.13.0/node_modules/@humanwhocodes/config-array/api.js:1028:39) at FlatConfigArray.isFileIgnored (/home/maxi/personal/eslint-reproduction-bug/node_modules/.pnpm/@humanwhocodes+config-array@0.13.0/node_modules/@humanwhocodes/config-array/api.js:1060:15) at /home/maxi/personal/eslint-reproduction-bug/node_modules/.pnpm/eslint@9.2.0/node_modules/eslint/lib/eslint/eslint-helpers.js:346:57 at Array.reduce () at /home/maxi/personal/eslint-reproduction-bug/node_modules/.pnpm/eslint@9.2.0/node_modules/eslint/lib/eslint/eslint-helpers.js:333:36 at /home/maxi/personal/eslint-reproduction-bug/node_modules/.pnpm/eslint@9.2.0/node_modules/eslint/lib/eslint/eslint-helpers.js:296:32 at Object.isAppliedFilter (/home/maxi/personal/eslint-reproduction-bug/node_modules/.pnpm/@nodelib+fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/readers/common.js:12:31)  ELIFECYCLE  Command failed with exit code 2. ```

It's probably a misconfiguration or I've missed something, but after re-reading everything I've been unable to find where the fault lies. Thanks in advance for your reply!

Steps

  1. pnpm dlx nuxi@latest init eslint-reproduction-bug
  2. cd eslint-reproduction-bug/ 3.
  3. pnpm install.
  4. pnpm run dev.
  5. Using the Nuxt DevTools, I installed the 'Eslint Module'
  6. Manually install eslint with pnpm i eslint (as explained in the manual. I was expecting it to be installed automatically from the DevTools).
  7. In the newly created eslint.config.mjs add the @antfu/eslint-config config.
  8. Update the eslint config in nuxt.config.ts.
  9. Add lint and lint:fix to package.json
  10. Run lint:fix. It will also ask for the extra eslint configuration I installed ("@unocss/eslint-plugin" and "eslint-plugin-format").
  11. The error will be shown

Reproduction

https://github.com/onmax/eslint-reproduction-bug

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics
    Memory: 1.35 GB / 7.45 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v20.10.0/bin/yarn
    npm: 10.2.5 - ~/.nvm/versions/node/v20.10.0/bin/npm
    pnpm: 9.1.0 - ~/.local/share/pnpm/pnpm
    bun: 1.0.20 - ~/.nvm/versions/node/v20.10.0/bin/bun

Used Package Manager

pnpm

Validations

Contributions

antfu commented 1 month ago

You should set standalone to false

onmax commented 1 month ago

Hey, I have updated the repro with standalone to false, but it still happening. I pushed the repro to github again

image

yimme commented 1 month ago

Ran into the same issue @onmax. running the nuxt app first with npm run dev fixed it for me.

onmax commented 1 month ago

Awesome thank you!

Now it seems to work, but now I get another weird eslint error:

maxi@maxi:~/personal/eslint-reproduction-bug$ nr lint:fix

> nuxt-app@ lint:fix /home/maxi/personal/eslint-reproduction-bug
> eslint . --fix

/home/maxi/personal/eslint-reproduction-bug/components/WelcomeItem.vue
  2:33  error  Parsing error: Unexpected token )

✖ 1 problem (1 error, 0 warnings)

 ELIFECYCLE  Command failed with exit code 1.
WelcomeItem.vue

```vue ```

Steps to reproduce:

  1. Clone onmax/eslint-reproduction-bug
  2. Run pnpm install and pnpm dev
  3. Kill server
  4. Run pnpm lint:fix or pnpm lint

Did I misconfigured something? It is valid Vue as it is working as expected in local dev. Thank you for your response 😃