Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot read config package for shareable config using global eslint #4822

Closed
kevinoid opened this issue Dec 28, 2015 · 4 comments
Closed
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion triage An ESLint team member will look at this issue soon

Comments

@kevinoid
Copy link
Contributor

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 
/usr/local/lib/node_modules/eslint/lib/config/config-file.js:332
            throw e;
            ^

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 /usr/local/lib/node_modules/eslint/lib/config/config-file.js:326:36
    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:

  1. eslint-config-algolia can be installed globally. The downside is that now developers must determine which eslint modules a project requires, then install them globally before linting. It's workable, but painful for developers, and especially painful to new project contributors who are more likely to either forgo linting or contributing.
  2. The extends declaration can be made relative in .eslintrc (e.g. by changing "extends": "algolia" to "extends": "./node_modules/eslint-config-algolia/index.js" or similar - and recursively for transitive dependencies). This appears to be a common idiom but it is both verbose and requires all transitive dependencies to use this strategy (which may be out of a project's control, and is not currently ubiquitous).
  3. eslint can always be invoked through the project-local installation in node_modules. This is both workable and has the added benefit of allowing projects to require a specific version of eslint. But it requires all programs which invoke eslint to comply, which is reasonably difficult to enforce on an ongoing basis. Nearly all programs I checked currently assume eslint is installed in $PATH, which does the right thing when invoked via npm run but the wrong thing when launched by a user (e.g. via editor tools).

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,
Kevin

Note: There is some overlap with #3458, and a solution to either issue might affect the other.

@eslintbot
Copy link

@kevinoid Thanks for the issue! If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Dec 28, 2015
@mysticatea
Copy link
Member

Thank you for this issue.

Related issues: #4529, #3293, #1238

eslint-cli might help you.

@nzakas
Copy link
Member

nzakas commented Dec 28, 2015

This is a known limitation. If you are using a globally installed ESLint, your shareable config must also be globally installed.

@nzakas nzakas closed this as completed Dec 28, 2015
@kevinoid
Copy link
Contributor Author

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?

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion triage An ESLint team member will look at this issue soon
Projects
None yet
Development

No branches or pull requests

4 participants