eslint-config-defaults
eslint-config-defaults copied to clipboard
ESLint Bug: extended config does not work with globally installed eslint
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 ."
}
Noted in the README here: https://github.com/walmartlabs/eslint-config-defaults#limitations
@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..
@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...
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.
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.
@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?
Ok this works, after I changed my .eslintrc.json file, because my json file looked like:
{
"extends": "google"
}
thx.
Hi All, is this still an issue? I'm using a globally-installed eslint
and am not having issues.
Yes, it's still a problem
try this npm install --save eslint-config-defaults
@j492 -- confirming this solves the issue after adding the global flag.
npm install --save -g eslint-config-defaults
@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