SublimeLinter ESLint找不到插件

时间:2019-07-03 23:44:38

标签: sublimetext eslint sublimelinter

在Sublime Text Editor 3.x中编辑javascript文件时,出现错误:

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.

我尝试了多种在线解决方案,包括删除全局ESLint /将所有与ESLint相关的软件包都移到全局,以及更改SublimeLinter.settings文件。该问题仅在通过Sublime运行皮棉时出现。当我运行eslint命令时,它运行正常。

如果有人知道为什么会发生这种情况,请帮助我!

谢谢

2 个答案:

答案 0 :(得分:0)

通常,您可能会将ESLint更新为 v6

按照Migrating to 6.0 Docs

如果您使用ESLint 全局安装(例如与npm install eslint --global一起安装)以及插件。

然后,您应该在运行ESLint的项目中本地安装这些插件。

在您的情况下,将eslint-plugin-chai-expect和其他插件(如果使用)以devDependencies的形式在您的项目中本地安装。

npm i -D eslint-plugin-chai-expect

如果您的配置文件扩展了可共享的配置和/或解析器,则应确保将这些软件包安装为包含该配置文件的项目的依赖项。

答案 1 :(得分:0)

据我所知,这确实是迁移到ESLint v6的问题。 但是这不是全局安装问题。

现在的问题是,ESLint在运行eslint命令的工作目录中查找。如您在your comment中所说:

  

它似乎在父文件夹中查找(正如您在错误中看到的那样,它在c:/workspace/flltools中查找,而我的项目在c:/workspace/flltools/modules/scoring

因此,您的编辑器在父目录中而不是package.json文件所在的目录中运行eslint。我猜您的编辑器的项目根目录比package.json文件所在的目录高一级。

看起来确实已经通过github问题#1626在SublimeLinter插件中对其进行了修补:Wrong working directory on nested local eslint installs (breaks eslint@6)

请注意,VSCode和Vim都有类似的问题,因此它不是Sublime Text特有的东西,而是ESLint。

在ESLint v6迁移文档中,其中有"Plugins and shareable configs are no longer affected by ESLint’s location"部分。它表明:

  

如果您使用本地项目之外的配置文件(带有--config标志),请考虑将插件安装为该配置文件的依赖项,并将--resolve-plugins-relative-to标志设置为配置文件。

--resolve-plugins-relative-to将解决此问题,因为您可以指定package.json所在位置的路径。