问题
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
回答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.
回答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 inc:/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.
来源:https://stackoverflow.com/questions/56879118/sublimelinter-eslint-couldnt-find-the-plugin