javascript: eslint-config-airbnb error

I’ve added "extends": "eslint-config-airbnb" to an empty .eslintrc file and when I run eslint app I get the following error. If I remove the extends and paste in the node_modules .eslint contents, it works fine. Any ideas? I ran npm install several times

Error: Cannot find module 'eslint-config-airbnb'
Referenced from: /Users/adam/projects/webpack-boiler/.eslintrc
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at loadConfig (/usr/local/lib/node_modules/eslint/lib/config.js:96:48)
    at /usr/local/lib/node_modules/eslint/lib/config.js:123:46
    at Array.reduceRight (native)
    at loadConfig (/usr/local/lib/node_modules/eslint/lib/config.js:111:36)
    at getLocalConfig (/usr/local/lib/node_modules/eslint/lib/config.js:225:23)
    at Config.getConfig (/usr/local/lib/node_modules/eslint/lib/config.js:363:22)
webpack-boiler|⇒
{
  "name": "meteor-webpack-react",
  "version": "0.0.1",
  "description": "A port of simple-todos to Webpack/React on the frontend",
  "repository": "https://www.github.com/jedwards1211/meteor-webpack-react",
  "devDependencies": {
    "babel-eslint": "^4.0.5",
    "babel-loader": "^5.1.2",
    "css-loader": "^0.15.3",
    "eslint": "^1.1.0",
    "eslint-config-airbnb": "0.0.7",
    "eslint-plugin-react": "^3.2.1",
    "node-libs-browser": "^0.5.2",
    "react-hot-loader": "^1.2.7",
    "react-router": "^0.13.3",
    "style-loader": "^0.12.3",
    "webpack": "^1.10.1",
    "webpack-dev-server": "^1.10.1"
  },
  "dependencies": {
    "babel": "^5.6.14",
    "babel-core": "^5.6.20",
    "classnames": "^2.1.3",
    "react": "^0.13.3",
    "react-router": "^0.13.3",
    "lodash": "^3.10.0"
  },
  "scripts": {
    "dev": "scripts/dev.sh",
    "prod": "scripts/prod.sh",
    "build": "scripts/build.sh",
    "test-built": "scripts/test-built.sh"
  },
  "author": "",
  "license": "MIT"
}
{
  "extends": "eslint-config-airbnb"
}

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 11
  • Comments: 37 (2 by maintainers)

Most upvoted comments

ah, you’re right, i see it there. However, when you run eslint app you’re not running the locally installed version of eslint - the local one should only be run under an npm run-script, which effectively adds node_modules/.bin to the PATH for you. Try ./node_modules/.bin/eslint app to confirm?

You still have to manually add the package to your package.json - try npm install --save eslint-config-airbnb

npm install -g eslint (note that --save and --save-dev don’t apply to global installs)

Thanks for the fast reply!

I tried npm install --save eslint-config-airbnb as well with the same result. I did add it to the package.json, it’s on line 11 under dev dependencies (also tried under reg. deps.) The module is also in node_modules.

Any other ideas?

Npm url: https://www.npmjs.com/package/eslint-config-airbnb-base

( export PKG=eslint-config-airbnb-base; npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest" )

.eslintrc.json before:

{ "extends": "airbnb" }

after:

{ "extends": "airbnb-base" }

Worked for me…

@gunar If you are referring to using this with syntastic, a trick I learned recently is to just configure b:syntastic_javascript_eslint_exec to point to the locally installed version of eslint if it exists otherwise fallback to the globally installed:

function! SyntasticESlintChecker()
  let l:npm_bin = ''
  let l:eslint = 'eslint'

  if executable('npm')
      let l:npm_bin = split(system('npm bin'), '\n')[0]
  endif

  if strlen(l:npm_bin) && executable(l:npm_bin . '/eslint')
    let l:eslint = l:npm_bin . '/eslint'
  endif

  let b:syntastic_javascript_eslint_exec = l:eslint
endfunction


let g:syntastic_javascript_checkers = ["eslint"]

autocmd FileType javascript :call SyntasticESlintChecker()

Credit to @gcorne

To run the locally installed version of eslint without typing ./node_modules/.bin/eslint ..., you can set up a script in package.json:

// package.json
{
    "scripts": {
      "lint": "eslint app"
    }
}

then just run npm run lint. If you installed eslint locally, it will use that executable otherwise look for a globally installed instance (or anything in your $PATH variable).

Updated: Fixed the vim function

(
  export PKG=eslint-config-airbnb;
  npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest"
)

Worked perfect for me 👍

Ooooh, that makes sense! It does run when I use ./node_modules/.bin/eslint app. However then syntastic breaks and won’t lint.

However this lead to me this issue which says that if I need to run eslint globally then I also need to install eslint-config-airbnb globally. I did this and now it works great. I can use your solution for my makefile and the global for syntastic (just have to make sure they’re in sync!).

Thanks!

{ "extends": "airbnb" } - this is airbnb config with all react support etc { "extends": "airbnb-base" } - this is airbnb config for just JS, and is now deprecated

What you need to run is npx install-peerdeps --dev eslint-config-airbnb

In my case I fixed it by: before:

npx eslint . --fix
Oops! Something went wrong! :(
ESLint: 6.1.0.
ESLint couldn't find the plugin "eslint-plugin-import".

run this:

rm -rf node_modules
npm install eslint --save
npm install eslint-config-airbnb-base --save
npm install eslint-plugin-markdown --save
npm install eslint-plugin-import --save
npm i
npx eslint --version
(should be less than 7)

it works:

npx eslint . --fix

Reason: It seems if libs listed under dev reps, eslint got updated automatically to 7.0 as I explain here later.

Still got this error when using atom with eslint local install. I am using this repo https://github.com/kriasoft/react-starter-kit.

Error: Cannot find module 'eslint-config-airbnb' Referenced from: /Users/xugaofan/developer/git/MyApp/.eslintrc
Error: Cannot find module 'eslint-config-airbnb'
Referenced from: /Users/xugaofan/developer/git/MyApp/.eslintrc
    at Function.Module._resolveFilename (module.js:334:15)
    at Function.Module._load (module.js:284:25)
    at Module.require (module.js:363:17)
    at require (module.js:382:17)
    at readConfigFromFile (/Users/xugaofan/.atom/packages/linter-eslint/node_modules/eslint/lib/config.js:155:44)
    at loadConfig (/Users/xugaofan/.atom/packages/linter-eslint/node_modules/eslint/lib/config.js:176:22)
    at /Users/xugaofan/.atom/packages/linter-eslint/node_modules/eslint/lib/config.js:207:46
    at Array.reduceRight (native)
    at loadConfig (/Users/xugaofan/.atom/packages/linter-eslint/node_modules/eslint/lib/config.js:191:36)
    at getLocalConfig (/Users/xugaofan/.atom/packages/linter-eslint/node_modules/eslint/lib/config.js:321:23)

I’d strongly recommend not using global installs (per https://github.com/eslint/eslint/issues/1238#issuecomment-55172447) but as long as it’s working for you, yay! 😃

I was having issues with this on my GatsbyJS site in VS Code.

As per https://www.npmjs.com/package/eslint-config-airbnb I ran

npx install-peerdeps --dev eslint-config-airbnb

This requires npm 5+

I did that already, same problem npm install -g --save-dev eslint-config-airbnb babel-eslint eslint-plugin-react eslint