Running the following steps, which currently installs ESLint v1.10.3, results in the following error:
$ npm install -g eslint
$ git clone -b v1.1.0 https://github.com/algolia/instantsearch.js.git
$ cd instantsearch.js
$ npm install
$ eslint index.js
Error: Cannot read config package: eslint-config-algolia
Error: Cannot find module 'eslint-config-algolia'
Referenced from: /tmp/instantsearch.js/.eslintrc
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at loadPackage (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:168:16)
at loadConfigFile (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:212:18)
at load (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:385:18)
at Array.reduceRight (native)
at applyExtends (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:309:28)
If the last command is replaced with ./node_modules/.bin/eslint index.js the command completes without error. The error appears to result from "extends": "algolia" being translated to require("eslint-config-algolia") which fails when run from a global eslint installation because eslint-config-algolia is not installed globally.
This has a few obvious workarounds:
There are likely other workarounds that I haven't considered. Even if such workarounds are generally straightforward, the current situation leaves some developers with an error message that they have to investigate and fix. It would be great if this pain could be avoided by a change to ESLint. For example, would it be possible to resolve referenced modules (config, plugin, etc.) relative to the current package and fallback to global resolution only if local resolution fails?
Thanks for considering,
Note: There is some overlap with #3458, and a solution to either issue might affect the other.
@kevinoid Thanks for the issue! If you're reporting a bug, please be sure to include:
Requesting a new rule? Please see Proposing a New Rule for instructions.
Thank you for this issue.
Related issues: #4529, #3293, #1238
eslint-cli might help you.
This is a known limitation. If you are using a globally installed ESLint, your shareable config must also be globally installed.
Thanks @mysticatea, that is very helpful indeed.
@nzakas, if this is a known issue, is it documented anywhere? Perhaps I overlooked it. It seems to be affecting a lot of people and certainly took a while for me to figure out. Would you consider adding an explanation to the error message which is printed when require fails so users are at least pointed in the right direction?