SublimeLinter ESLint couldn't find the plugin
Asked Answered
C

2

2

When editing javascript files in Sublime Text Editor 3.x, I get the error:

Oops! Something went wrong! :(

ESLint: 6.0.1.

ESLint couldn't find the plugin "eslint-plugin-chai-expect".

(The package "eslint-plugin-chai-expect" was not found when loaded as a Node module from the directory "C:\workspace\flltools".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

    npm install eslint-plugin-chai-expect@latest --save-dev

The plugin "eslint-plugin-chai-expect" was referenced from the config file in "modules\scoring\.eslintrc.yml".

If you still can't figure out the problem, please stop by https://gitter.im/eslint/eslint to chat with the team.

I tried multiple solutions I found online, including removing global ESLint/moving all ESLint related packages to be global, to altering the SublimeLinter.settings file. The problem only occours when running lint through Sublime. When I run eslint command, it works perfectly.

If anyone has any idea why this is happenning please help me!

Thank you

Cyclopedia answered 3/7, 2019 at 23:44 Comment(0)
T
2

As far as I can tell this is indeed a problem with migrating to ESLint v6. But it's not a global installation problem.

The problem is now that ESLint looks in the working directory where the eslint command is run from. As you say in your comment:

It seems to be looking in a parent folder (as you can see in the error it's looking in c:/workspace/flltools, whereas my project is in c:/workspace/flltools/modules/scoring

So your editor is running eslint in the parent directory rather than in the directory where the package.json file is. I'm guessing your editor has the project root one level higher than where the package.json file is.

It does look like this has now been patched in the SublimeLinter plugin via github issue #1626: Wrong working directory on nested local eslint installs (breaks eslint@6)

Note that I have similar issues with both VSCode and Vim, so it's not a specifically a Sublime Text thing, more just an ESLint thing.

In the ESLint v6 migration doc, it has a section on "Plugins and shareable configs are no longer affected by ESLint’s location". It suggests:

If you use a config file located outside of a local project (with the --config flag), consider installing the plugins as dependencies of that config file, and setting the --resolve-plugins-relative-to flag to the location of the config file.

This --resolve-plugins-relative-to will fix the problem in that you can specify the path to where the package.json is inside there.

Tympanites answered 28/10, 2019 at 13:37 Comment(0)
U
1

Most probably you have updated your ESLint to v6.

As per Migrating to 6.0 Docs

If you use a global installation of ESLint (e.g. installed with npm install eslint --global) along with plugins.

Then you should install those plugins locally in the projects where you run ESLint.

In your case, Install eslint-plugin-chai-expect and other plugins(if used) as devDependencies locally to your project.

npm install --save-dev eslint-plugin-chai-expect

If your config file extends shareable configs and/or parsers, you should ensure that those packages are installed as dependencies of the project containing the config file.

Urtication answered 4/7, 2019 at 10:41 Comment(4)
Yes, they are. In my package.json, I have those devDependencies. It seems to be looking in a parent folder (as you can see in the error it's looking in c:/workspace/flltools, whereas my project is in c:/workspace/flltools/modules/scoring. Maybe that has something to do with the problem? I checked and there's no package.json in that directory.Cyclopedia
I just looked at the original project containing my shared file, eslint-plugin-chai-expect is in optionalDependencies. Do you think that might be a problem?Cyclopedia
Yeah may be as per docs, If config files are sharable then make them as dependencies and see does it works or not.Urtication
When I work with Sublime, I open an entire project (called flltools in this case). I found out the problem doesn't reproduce if in Sublime I open only the current repository (i.e. flltools/modules/scoring). I think maybe for some reason it's searching the package.json only in the root directory...Cyclopedia

© 2022 - 2024 — McMap. All rights reserved.