eslint-plugin-jsx-a11y: First line of all JSX / JS files gives lint error 'jsx-a11y/img-has-alt' was not found

I’m not sure if my configuration is setup improperly, but i appear to be given many lint errors of one particular type on each and every JS / JSX file on the first line, regardless of whether or not my React component contains an <img/> element. The error i get is:

[eslint] Definition for rule 'jsx-a11y/img-has-alt' was not found (jsx-a11y/img-has-alt)

Attached below is a GIF of what i am seeing in my IDE (Visual Studio Code). jsx-a11y-bug-img-has-alt

Below is a copy of my .eslintrc.json config:

{
    "extends": "airbnb",
    "plugins": [
        "react",
        "jsx-a11y",
        "import"
    ]
}

Below is a snippet from package.json file of my devDependencies (with version numbers):

"devDependencies": {
    "eslint": "^3.19.0",
    "eslint-config-airbnb": "^14.1.0",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^5.0.0",
    "eslint-plugin-react": "^7.0.0"
}

Have i missed a step in the configuration, or is this a bug?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 13
  • Comments: 27 (13 by maintainers)

Most upvoted comments

Thanks @ljharb.

I downgraded the dependency down to eslint-plugin-jsx-a11y@^4.0.0, and the lint error [eslint] Definition for rule 'jsx-a11y/img-has-alt' was not found (jsx-a11y/img-has-alt) disappeared from all JS / JSX files.

The Yarn command i used to downgrade the dependency from ^5.0.0 to ^4.0.0 is set out below:

yarn upgrade eslint-plugin-jsx-a11y@^4.0.0 --dev

The airbnb config is not yet compatible with v5 - it requires v4. Run npm ls and you’ll see that your dependencies are invalid.

The readme for the Airbnb config has a command that installs the proper version of peer deps - that’s the only way you should upgrade any of the peer deps the config requires.

@stepankuzmin i think it’s actually react-scripts thats pulling in eslint-config-react-app. This should be resolved when https://github.com/facebookincubator/create-react-app/pull/2163 is published!

@hundsim Specifically, I said that getting the latest version of everything the airbnb config requires (including the airbnb config itself) would solve the problem. Are you on the latest eslint, airbnb config, and is npm ls exiting successfully?

@ljharb version 15.0.1 of eslint-config-airbnb requires eslint-plugin-jsx-a11y@^5.0.1 and I still run to the same issue having both of these packages above…

I installed everything via:

export PKG=eslint-config-airbnb;
npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs yarn add -D "$PKG@latest"

Edit

I actually removed all my node_modules and installed them again and I get: image

plus in VSCode the same error as I mentioned above