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

ESLint Bug: extended config does not work with globally installed eslint #43

Open
baer opened this issue Dec 23, 2015 · 12 comments
Open

Comments

@baer
Copy link
Contributor

baer commented Dec 23, 2015

When running lint (eslint .) from a globally installed version of eslint (npm install -g eslint) you will get the following error. This appears to be a problem with ESLint itself.

package.json

dependencies: {
  "eslint-config-defaults": "^7.x.x",
  "eslint": "^1.10.3"
}
eslint .
/Users/ebaer/.nvm/versions/node/v5.2.0/lib/node_modules/eslint/lib/config/config-file.js:332
            throw e;
            ^

Error: Cannot read config package: eslint-config-defaults/configurations/walmart/es6-browser
Error: Cannot find module 'eslint-config-defaults/configurations/walmart/es6-browser'
Referenced from: /Users/ebaer/dev/tmp/builder-test/.eslintrc
    at Function.Module._resolveFilename (module.js:327:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:355:17)
    at require (internal/module.js:13:17)
    at loadPackage (/Users/ebaer/.nvm/versions/node/v5.2.0/lib/node_modules/eslint/lib/config/config-file.js:168:16)
    at loadConfigFile (/Users/ebaer/.nvm/versions/node/v5.2.0/lib/node_modules/eslint/lib/config/config-file.js:212:18)
    at load (/Users/ebaer/.nvm/versions/node/v5.2.0/lib/node_modules/eslint/lib/config/config-file.js:385:18)
    at /Users/ebaer/.nvm/versions/node/v5.2.0/lib/node_modules/eslint/lib/config/config-file.js:326:36
    at Array.reduceRight (native)
    at applyExtends (/Users/ebaer/.nvm/versions/node/v5.2.0/lib/node_modules/eslint/lib/config/config-file.js:309:28)

Workarounds:

  • Run the version of eslint inside your project's node_modules: ./node_modules/.bin/eslint .
  • Use npm scripts since they automatically check local node_modules first: npm run lint
scripts: {
  "lint": "eslint ."
}
@baer baer changed the title Does not work with globally installed eslint ESLint Bug: extended config does not work with globally installed eslint Dec 23, 2015
@baer
Copy link
Contributor Author

baer commented Dec 23, 2015

@mrmartineau
Copy link

@baer, is there a way around this limitation? I would like to use Sublime/Atom eslint plugins as well as grunt-eslint and these configs do not work..

@ryan-roemer
Copy link
Contributor

@mrmartineau -- The code blowing up is here: https://github.com/eslint/eslint/blob/master/lib/config/config-file.js#L159-L175

function loadPackage(filePath) {
    debug("Loading config package: " + filePath);
    try {
        return require(filePath);
    } catch (e) {
        debug("Error reading package: " + filePath);
        e.message = "Cannot read config package: " + filePath + "\nError: " + e.message;
        throw e;
    }
}

Which is essentially just a require(). A require from a global install isn't going to look in CWD.

Offhand, one option is to globally install the same configs that a global eslint is using. Another would be update NODE_PATH to include path.join(process.cwd(), "node_modules") or something...

@kevinoid
Copy link
Contributor

kevinoid commented Feb 6, 2016

For reference, this is a known issue in eslint which the other shareable config projects are encountering as well (e.g. google/eslint-config-google#3, airbnb/javascript#465).

As noted in the eslint issue, eslint-cli may be an option for some users. A shell alias may work for others. I think eslint is probably the place to fix it permanently, but the README does well to make users aware until/unless that happens.

@Chris2011
Copy link

I do this inside a project folder:

C:\Users\username\AppData\Roaming\npm\eslint.cmd --config .eslintrc.json --format compact .

got the same issue with eslint-config-google. Is there a workaroung for now? can't use eslint for my projects... Use Windows 10 64Bit. If you need more info, let me know it. Or whether I have to create the comment to another repo.

@ryan-roemer
Copy link
Contributor

@Chris2011 -- Try a local install of eslint in your project:

$ npm install eslint --save-dev

Then add an npm scripts command like:

"lint": "eslint --config .eslintrc.json --format compact ."

Then try:

$ npm run lint

in your project and see if that works?

@Chris2011
Copy link

Ok this works, after I changed my .eslintrc.json file, because my json file looked like:

{
   "extends": "google"
}

thx.

@seanknox
Copy link

seanknox commented May 2, 2016

Hi All, is this still an issue? I'm using a globally-installed eslint and am not having issues.

@LordDelacroix
Copy link

Yes, it's still a problem

@j492
Copy link

j492 commented Nov 8, 2016

try this
npm install --save eslint-config-defaults

@DerekZiemba
Copy link

DerekZiemba commented Dec 2, 2016

@j492 -- confirming this solves the issue after adding the global flag.

npm install --save -g eslint-config-defaults

@j492
Copy link

j492 commented Dec 3, 2016

@darekziemba Yes it will also work. -g option install it globally which will let you use this lib in any folder on your machine. I don't use -g as the versions change frequently and I want to use latest available on later projects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

9 participants