AtomLinter / linter-eslint

ESLint plugin for Atom Linter
https://atom.io/packages/linter-eslint
584 stars 141 forks source link

Linter cannot find shared configruation within locally installed packages #489

Closed keirlawson closed 7 years ago

keirlawson commented 8 years ago

When I try to extend a specific configuration within a shared configuration module which has been locally installed like so:

extends: 'connections-sdk/angular'

I get the following error:

Error: Cannot find module 'eslint-config-connections-sdk/angular' from '/home/keir/.dotfiles/.atom/packages/linter-eslint/node_modules'
Referenced from: /home/keir/Code/Angular/cc_caesium_plugin_mixed_media/src/simulator/.eslintrc.yaml
    at Function.module.exports [as sync] (/home/keir/.dotfiles/.atom/packages/linter-eslint/node_modules/eslint/node_modules/resolve/lib/sync.js:33:11)
    at resolve (/home/keir/.dotfiles/.atom/packages/linter-eslint/node_modules/eslint/lib/config/config-file.js:417:38)
    at load (/home/keir/.dotfiles/.atom/packages/linter-eslint/node_modules/eslint/lib/config/config-file.js:436:24)
    at /home/keir/.dotfiles/.atom/packages/linter-eslint/node_modules/eslint/lib/config/config-file.js:355:36
    at Array.reduceRight (native)
    at applyExtends (/home/keir/.dotfiles/.atom/packages/linter-eslint/node_modules/eslint/lib/config/config-file.js:338:28)
    at Object.load (/home/keir/.dotfiles/.atom/packages/linter-eslint/node_modules/eslint/lib/config/config-file.js:464:22)
    at loadConfig (/home/keir/.dotfiles/.atom/packages/linter-eslint/node_modules/eslint/lib/config.js:67:33)
    at new Config (/home/keir/.dotfiles/.atom/packages/linter-eslint/node_modules/eslint/lib/config.js:192:38)
    at CLIEngine.executeOnText (/home/keir/.dotfiles/.atom/packages/linter-eslint/node_modules/eslint/lib/cli-engine.js:665:28)
lucasmotta commented 8 years ago

Same here after a recent update.

Error: Failed to load plugin react: Cannot find module 'eslint-plugin-react'

Even thou eslint-plugin-react is installed.

Arcanemagus commented 8 years ago

@keirlawson and @lucasmotta: What is the exact folder structure of your project? Can you post the eslint configuration and the package dependencies? Does eslint from the command line work?

ghost commented 8 years ago

Within the last 1-2 months i had this bug fixed and reintroduced 3 times. It was working fine for a few days with the release of linter-eslint 7.0, then it broke again shortly afterwards. The first time i encountered this issue i was thinking it is because of my settings and tried to fix it, but all i have is a locally installed eslint-config-standard and eslint-plugin-standard. since it worked perfectly fine a few times and also always simultaneously broke on other projects on other machines i assume it is an issue with this plugin.

Edit: I gave it another look - the issue seems to be that it is calling the global eslint instance which cant call a global eslint-config-standard (because there is none). when i change to my local project directory and run eslint *.js, it gives me the same error message as the plugin does. when i run ./node_modules/.bin/eslint *.js it works fine.

inside my package.json:

"devDependencies": {
    "eslint-config-standard": "*",
    "eslint-plugin-standard": "*"
}

i made extra sure the node modules were correctly installed with npm insall

shodanuk commented 8 years ago

Similar issue here.

Stacktrace (partial):

Error: Failed to load plugin react: Cannot find module 'eslint-plugin-react'
    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)

Package.json:

"devDependencies": {
    ...
    "eslint": "^2.4.0",
    "eslint-plugin-react": "^4.2.3",
    ...
}

No global eslint installed.

Atom config.json:

{
...
"linter-eslint":
  globalNodePath: "/Users/terrymorgan/.nvm/versions/node/v4.2.6"
...
}

.eslintrc.json:

{
    "env": {
        "commonjs": true,
        "es6": true,
        "node": true
    },
    "extends": "eslint:recommended",
    "parserOptions": {
        "ecmaFeatures": {
            "experimentalObjectRestSpread": true,
            "jsx": true
        },
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "indent": [
            2,
            4
        ],
        "linebreak-style": [
            2,
            "unix"
        ],
        "quotes": [
            2,
            "double"
        ],
        "semi": [
            2,
            "always"
        ]
    }
}

Eslint from the CLI works with:

./node_modules/.bin/eslint *.js

Screengrab of folder structure is attached.

unspecified

ErikBean commented 8 years ago

FWIW, I am having the exact same issue as @shodanuk with linter-eslint not finding locally-installed eslint-plugin-react

mrfelton commented 8 years ago

I have a similar issue using the scoped package from https://github.com/fullcube/eslint-config-fullcube with a .eslintrc file like this:

{
  "extends": "@fullcube/eslint-config-fullcube",
  "root": true
}

Error: Cannot read config file: /Users/tom/workspace/loopback-component-fsm/node_modules/@fullcube/eslint-config-fullcube/node_modules/eslint-config-strict/es6.js Error: ENOENT: no such file or directory, open '/Users/tom/workspace/loopback-component-fsm/node_modules/@fullcube/eslint-config-fullcube/node_modules/eslint-config-strict/es6.js' Referenced from: @fullcube/eslint-config-fullcube Referenced from: /Users/tom/workspace/loopback-component-fsm/.eslintrc

It seems to be looking for eslint-config-strict in the wrong place. The package exists in the top level node_modules, not the one within the scoped eslint shared config.

Note: eslint-config-strict is not installed as a top level dependency - it is listed as a dependency of eslint-config-fullcube.

mansona commented 8 years ago

Ok so I was having some of the same issues here and I was able to fix one of them and get going. This is a work around so it would probably be good to get fixed in linter-eslint.

I'm not sure what people mean by "locally installed packages" but npm linking @stonecircle/eslint-config does not work. So I published it and it was able to be picked up and it's now working.

fthebaud commented 8 years ago

Same problem here. Configuration:

The following packages are installed locally

.eslintrc.js configuration: extends: ['eslint:recommended', 'eslint-config-angular'],

Error: Cannot find module 'eslint-config-angular' 2

Workaround: I had to install eslint, eslint-plugin-angular and eslint-plugin-config globally and use the global eslint installation in atom. 3

IanVS commented 8 years ago

@fthebaud it looks like you did not have eslint-config-angular installed locally as instructed by https://github.com/Gillespie59/eslint-plugin-angular#usage-with-shareable-config ?

IanVS commented 8 years ago

Or, was eslint-plugin-config a typo and you meant eslint-config-angular?

fthebaud commented 8 years ago

Yes it was typo, sorry about that

jaydenseric commented 8 years ago

Wierd, after reinstalling all my project npm dependencies several times and still getting the error popup I ran npm cache clean, restarted Atom, and the problem went away. It was probably the restart that did the trick.

IanVS commented 7 years ago

For those of you having this problem, can you please upgrade to linter-eslint: 8.0.0 and then run Linter Eslint: Debug from the command palette, pasting the output here? This will verify whether linter-eslint is using the local or global ESLint.

IanVS commented 7 years ago

Closing due to lack of response. If anyone is still having problems, please post the requested information and we can reevaluate.

Redsandro commented 7 years ago

@IanVS same problem here.

linter-eslint: debug

Atom version: 1.15.0
linter-eslint version: 8.1.4
ESLint version: 3.17.1
Hours since last Atom restart: 0.1
Platform: linux
Using bundled fallback ESLint from: /home/me/.atom/packages/linter-eslint/node_modules/eslint
Current file's scopes: [
  "source.js",
  "meta.function.js",
  "meta.parameters.js",
  "meta.delimiter.object.comma.js"
]
linter-eslint configuration: {
  "lintHtmlFiles": false,
  "useGlobalEslint": false,
  "showRuleIdInMessage": true,
  "disableWhenNoEslintConfig": true,
  "eslintrcPath": "",
  "globalNodePath": "",
  "advancedLocalNodeModules": "",
  "eslintRulesDir": "",
  "disableEslintIgnore": false,
  "disableFSCache": false,
  "fixOnSave": false,
  "scopes": [
    "source.js",
    "source.jsx",
    "source.js.jsx",
    "source.babel",
    "source.js-semantic"
  ],
  "rulesToSilenceWhileTyping": [],
  "rulesToDisableWhileFixing": []
}

Error: Cannot find module 'eslint-config-angular' Referenced from: /var/www/test/.eslintrc

Error: Cannot find module 'eslint-config-angular'
Referenced from: /var/www/test/.eslintrc
    at ModuleResolver.resolve (/home/me/.atom/packages/linter-eslint/node_modules/eslint/lib/util/module-resolver.js:74:19)
    at resolve (/home/me/.atom/packages/linter-eslint/node_modules/eslint/lib/config/config-file.js:485:25)
    at load (/home/me/.atom/packages/linter-eslint/node_modules/eslint/lib/config/config-file.js:502:26)
    at configExtends.reduceRight.e (/home/me/.atom/packages/linter-eslint/node_modules/eslint/lib/config/config-file.js:391:36)
    at Array.reduceRight (native)
    at applyExtends (/home/me/.atom/packages/linter-eslint/node_modules/eslint/lib/config/config-file.js:362:28)
    at Object.load (/home/me/.atom/packages/linter-eslint/node_modules/eslint/lib/config/config-file.js:536:22)
    at loadConfig (/home/me/.atom/packages/linter-eslint/node_modules/eslint/lib/config.js:63:33)
    at new Config (/home/me/.atom/packages/linter-eslint/node_modules/eslint/lib/config.js:229:42)
    at CLIEngine.executeOnText (/home/me/.atom/packages/linter-eslint/node_modules/eslint/lib/cli-engine.js:741:28)

.eslintrc

{
    "env": {
        "browser": true
    },
    "extends": ["eslint:recommended", "angular"],
    "rules": {
        "indent": [
            1,
            4
        ],
        "linebreak-style": [
            2,
            "unix"
        ],
        "semi": [
            1,
            "always"
        ]
    }
}

$ npm ls --global --depth=1

/home/me/.nvm/versions/node/v4.2.6/lib
├── bower@1.8.0
├── eslint-config-angular@0.5.0
├── eslint-plugin-angular@2.2.0
├─┬ jshint@2.9.2
├─┬ npm@2.14.12
IanVS commented 7 years ago

@Redsandro you need to also install eslint within your project (yarn add --dev eslint or npm i --save-dev eslint). Your linter-eslint is falling back to the one it bundles, but you can't use that with plugins or shared configs in your project directory.

Redsandro commented 7 years ago

@IanVS the problem is that the rules cannot be used globally. You are correct, installing everything locally for every project makes them work correctly. I hadn't tried installing the rules locally.

For people who google: All three need to be installed locally.

"eslint": "^3.18.0",
"eslint-config-angular": "^0.5.0",
"eslint-plugin-angular": "^2.2.0"
IanVS commented 7 years ago

the problem is that the rules cannot be used globally

They can be, if you install eslint and all of the plugins globally. We generally don't recommend that, though. It's better to specify the linting dependencies on a per-project basis.

Redsandro commented 7 years ago

They can be, if you install eslint and all of the plugins globally.

Are you sure about that? That's how I started out, and I got the error message.

IanVS commented 7 years ago

From the debug you posted, "useGlobalEslint": false, and Using bundled fallback ESLint tells me that you did not have eslint installed globally, you were using the fallback.

When I say globally installed, I mean installed with npm i -g eslint eslint-config-angular eslint-plugin-angular. But again, we don't generally recommend that.

Redsandro commented 7 years ago

@IanVS I was going to quote myself and say that the debug output must be wrong, but then

@Redsandro said:

$ npm ls --global --depth=1

/home/me/.nvm/versions/node/v4.2.6/lib
├── bower@1.8.0
├── eslint-config-angular@0.5.0
├── eslint-plugin-angular@2.2.0
├─┬ jshint@2.9.2
├─┬ npm@2.14.12

I realized I had installed jshint in stead of eslint. Mea culpa. :sweat_smile:

we don't generally recommend that.

Noted.