nuxt / eslint

Collection of ESLint-related packages for Nuxt
https://eslint.nuxt.com
MIT License
543 stars 66 forks source link

Using this extension with create-nuxt-app results in 'definition for rule ... not found' errors #134

Closed timfee closed 6 months ago

timfee commented 3 years ago

With a vanilla eslint config (below),

module.exports = {
  root: true,
  parserOptions: {
    parser: 'babel-eslint',
    sourceType: 'module',
  },
  env: {
    browser: true,
    node: true,
  },
  extends: [
    '@nuxtjs/eslint-config-typescript',
    'prettier',
    'prettier/vue',
    'plugin:prettier/recommended',
    'plugin:nuxt/recommended',
  ],
  plugins: ['prettier'],
  // add your custom rules here
  rules: {},
}

As long as '@nuxtjs/eslint-config-typescript' is included, VS Code shows a bunch of Vue errors:

Screen Shot 2020-12-23 at 8 45 49 AM

My package.json is:

{
  "name": "cal",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "nuxt-ts",
    "build": "nuxt-ts build",
    "start": "nuxt-ts start",
    "generate": "nuxt-ts generate",
    "lint:js": "eslint --ext .js,.vue --ignore-path .gitignore .",
    "lint": "npm run lint:js"
  },
  "dependencies": {
    "@nuxt/typescript-runtime": "^2.0.0",
    "@nuxtjs/axios": "^5.12.4",
    "core-js": "^3.8.1",
    "nuxt": "^2.14.12"
  },
  "devDependencies": {
    "@nuxt/types": "^2.14.12",
    "@nuxt/typescript-build": "^2.0.3",
    "@nuxtjs/eslint-config": "^5.0.0",
    "@nuxtjs/eslint-config-typescript": "^5.0.0",
    "@nuxtjs/eslint-module": "^3.0.2",
    "@nuxtjs/tailwindcss": "^3.4.2",
    "babel-eslint": "^10.1.0",
    "eslint": "^7.16.0",
    "eslint-config-prettier": "^7.1.0",
    "eslint-plugin-nuxt": "^2.0.0",
    "eslint-plugin-prettier": "^3.3.0",
    "prettier": "^2.2.1"
  }
}

I'm not sure this is the right project, but as it seemed to be the one that impacted the results, I figured I'd start here :) Apologies if I got something basic wrong!

timfee commented 3 years ago

Update: it looks like I had to install eslint-plugin-vue manually

kazuemon commented 3 years ago

Facing the same problem

module.exports = {
  root: true,
  env: {
    browser: true,
    node: true,
  },
  extends: [
    '@nuxtjs/eslint-config-typescript',
    'plugin:nuxt/recommended',
    'plugin:prettier/recommended',
    'prettier',
    'prettier/vue',
  ],
  rules: {
    'no-unused-vars': 'off',
    '@typescript-eslint/no-unused-vars': 'error',
  },
}
kazuemon commented 3 years ago

MEMO: @nuxtjs/eslint-config (load from @nuxtjs/eslint-config-typescript) is using eslint-plugin-vue https://github.com/nuxt/eslint-config/blob/master/packages/eslint-config/package.json

kazuemon commented 3 years ago

( Google Translate )

The cause is unknown, but once I specified v3.0.0 and reinstalled it, and then updated to v5.0.0, the error no longer occurred (I'm not sure if it's working properly).

danny-pearson commented 3 years ago

I had the same issue, but I managed to get it sorted after a little playing around. Not sure how necessary a couple of the steps were, but it's working fine now :) There should be no need to install eslint-plugin-vue manually, because it's already included in this package.

I updated eslint to the latest version (I believe it needs to be anything > 7.13.0). I stripped down my .eslintrc.js because some properties (e.g parser) are already included in the configs and overriding them could be causing issues. I deleted yarn.lock and the node_modules folder, ran yarn cache clean then reinstalled. I restarted VSCode. This is when the error disappeared, and strangely enough I've had similar issues before that have eventually been fixed this way.

My .eslintrc.js ended up like this.

module.exports = {
  root: true,
  extends: [
    '@nuxtjs',
    'airbnb-base',
    'plugin:nuxt/recommended',
  ],
  plugins: [
    'prettier',
  ],
  globals: {
    $nuxt: true,
  },
  // ... settings, rules etc...
};
danny-pearson commented 3 years ago

Feel like .eslintcache may have something to do with this issue also.

clarkdo commented 3 years ago

This may also be related to npm/yarn hoisting or vscode cache, I suggest reinstalling dependencies and reload vscode window, if it's still now working, let's add eslint-plugin-vue explicitly which can make it be installed at root node_modules.

antfu commented 6 months ago

We temporarily closed this due to the lack of enough information. We could not identify whether it was a bug or a userland misconfiguration with the given info. Please provide a minimal reproduction to reopen the issue. Thanks.

Why reproduction is required