Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Linting in nested app causes Error: Cannot read config package #422

Closed
davidhouweling opened this issue Feb 1, 2016 · 26 comments
Closed

Comments

@davidhouweling
Copy link

The structure of my present project is as followed:

project
    node_modules
        eslint
        eslint-config-airbnb
    test
        foo.spec.js
    webroot
        private
            node_modules
            src
                foo.js
            package.json
        public
    .eslintrc
    package.json

So when editing foo.spec.js, it goes up the path and picks up the .eslintrc file, and loads eslint-config-airbnb (specified in .eslintrc) at the root level node_modules. However, when editing foo.js, it does recognise that it should load eslint-config-airbnb, but it attempts to resolve it from project/webroot/private/node_modules and not project/node_modules.

It gives the following error

Error: Cannot read config package: eslint-config-airbnb
Error: Cannot find module 'eslint-config-airbnb'
Referenced from: C:\git\project\.eslintrc
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at loadPackage (C:\Users\<user>\.atom\packages\linter-eslint\node_modules\eslint\lib\config\config-file.js:168:16)
    at loadConfigFile (C:\Users\<user>\.atom\packages\linter-eslint\node_modules\eslint\lib\config\config-file.js:212:18)
    at load (C:\Users\<user>\.atom\packages\linter-eslint\node_modules\eslint\lib\config\config-file.js:385:18)
    at C:\Users\<user>\.atom\packages\linter-eslint\node_modules\eslint\lib\config\config-file.js:326:36
    at Array.reduceRight (native)
    at applyExtends (C:\Users\<user>\.atom\packages\linter-eslint\node_modules\eslint\lib\config\config-file.js:309:28)
@Arcanemagus
Copy link
Member

Does eslint itself work in that situation?

cd C:\git\project\webroot\private\src
eslint foo.js

Also it looks like you are trying to use the built in version of eslint instead of one installed to the project, this isn't really recommended, any reason you don't have eslint listed as a devDependency of the project?

@davidhouweling
Copy link
Author

sorry, i do have eslint installed at project level as a devDependency. Just forgot to include it, edited now. eslint command wouldn't work at that level because it isn't in the inner package.json file (as I don't want/need it there). I would be running eslint from the root level, covering all subfiles.

@Arcanemagus
Copy link
Member

So the reason I thought you didn't have it installed there is because the linter-eslint package is using it's built in eslint instance instead of the one at the project level, which is probably just a symptom of the same issue.

@davidhouweling
Copy link
Author

Yea, anything I can do to help resolve this?

@Arcanemagus
Copy link
Member

Finally took some time to try to reproduce this, and it looks like eslint does work on the command line, but only if you specify the path to the eslint binary manually. @AtomLinter/linter-eslint is this an issue that we should be fixing, or is this a configuration issue as eslint can't be found from the standard methods?

image

@davidhouweling
Copy link
Author

potentially it could be that it should check it based on the location of the eslintrc file?

@IanVS
Copy link
Member

IanVS commented Feb 4, 2016

Unfortunately we can't assume that the presence of an .eslintrc file indicates the root of a project, because of the way that configurations cascade in ESLint. There could be an .eslintrc file in every directory in the project. A slightly more reliable way is by finding an .eslintignore file, since those do not cascade. But even then, it's not guaranteed to live at the root. You could try adding a .eslintignore file at the outer level. That may actually trigger linter-eslint to look in the correct node_modules (but no promises).

@davidhouweling
Copy link
Author

@IanVS thanks for the input. Unfortunately that is the present setup I already have (i.e. an .eslintignore at the project root).

@IanVS
Copy link
Member

IanVS commented Feb 4, 2016

@Arcanemagus I think our only real shot here would be to give something like node-which another try. I believe that would solve this particular case, at least.

@Arcanemagus
Copy link
Member

If you mean npm-which, it completely fails to resolve the modules from that folder. (It finds the global eslint as the "nearest", and doesn't find eslint-config-airbnb at all).

@davidhouweling
Copy link
Author

any update on this?

@IanVS
Copy link
Member

IanVS commented Feb 18, 2016

I'm surprised to hear that npm-which doesn't work in this case. @timoxley, can you tell if this is a situation which it should be able to handle correctly?

@dijs
Copy link

dijs commented Feb 18, 2016

I am also seeing this issue. atom linter-eslint cannot find airbnb module.

@dijs
Copy link

dijs commented Feb 18, 2016

If anyone needs a hack to get this working, install the modules needed directly into your atom package.

Like this: #259

@Arcanemagus
Copy link
Member

@dijs What is your project's structure that isn't working? Does eslint from the command line work?

@dijs
Copy link

dijs commented Feb 18, 2016

Yes. It does.

@Arcanemagus
Copy link
Member

@dijs The first question was just as important 😉.

@dijs
Copy link

dijs commented Feb 18, 2016

Sorry. I don't really understand what you are asking there. linter-eslint errors out because it cannot find the airbnb module I have locally installed.

@IanVS
Copy link
Member

IanVS commented Feb 18, 2016

Can you explain your structure, similar to #422 (comment) ?

@dijs
Copy link

dijs commented Feb 18, 2016

Oh sure.

node_modules
   babel
   babel-eslint
   eslint
   eslint-config-airbnb
   eslint-plugin-react
src
   stuff.js
.eslintignore
.eslintrc.js
package.json

@Arcanemagus
Copy link
Member

What version of linter-eslint and Atom are you using? That structure should work perfectly fine...

@dijs
Copy link

dijs commented Feb 18, 2016

Atom: 1.5.3
linter-eslint: 6.0.0
linter: 1.11.3

@IanVS
Copy link
Member

IanVS commented Feb 18, 2016

I'd suggest opening a new issue, since this issue is for something entirely different.

@dijs
Copy link

dijs commented Feb 18, 2016

Created #445

@timoxley
Copy link

If you mean npm-which, it completely fails to resolve the modules from that folder.

@Arcanemagus This was true, but should no longer be with the latest npm-which. If it doesn't please open an issue.

I'm surprised to hear that npm-which doesn't work in this case. @timoxley, can you tell if this is a situation which it should be able to handle correctly?

@IanVS Yes, it should!

@Arcanemagus
Copy link
Member

Just retested this issue and it seems to have been fixed by an update to eslint or linter-eslint since this was filed. Marking as closed.

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

No branches or pull requests

5 participants