繁体   English   中英

Eslint:如何使用全局安装的 eslint-plugin-vue

[英]Eslint: How to use globally installed eslint-plugin-vue

我想使用linter elint-plugin-vue作为全局安装,因为我经常使用 Docker,而且我的存储库的根目录中可能没有node_modules文件夹。
以前,我已经像这样安装了 linter: sudo npm install -g eslint eslint-plugin-vue vue-eslint-parser

但是,在没有任何node_modules文件夹的情况下运行/usr/bin/eslint --ext.vue Footer.vue时,我得到以下信息:

Oops! Something went wrong! :(

ESLint: 7.23.0

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "/home/user".)

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

    npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in "PersonalConfig".

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

ls -la /usr/lib/node_modules/ | grep lint ls -la /usr/lib/node_modules/ | grep lint显示:

drwxr-xr-x   7 root root   4096 30. Mär 18:56 eslint
drwxr-xr-x   4 root root   4096 30. Mär 18:56 eslint-plugin-vue
drwxr-xr-x   8 root root   4096 19. Mär 23:09 jsonlint
drwxr-xr-x   3 root root   4096 30. Mär 21:43 vue-eslint-parser

~/.eslintrc :

{
  "extends": [
    "eslint:recommended",
    "plugin:vue/vue3-recommended"
  ]
}

一旦我将"plugin:vue/vue3-recommended"放入~/.eslintrc中,就会弹出上述错误。
有没有办法使这项工作? 如果我正在使用的存储库在本地没有node_modules ,那么将它作为后备会很棒。

您可以使用--resolve-plugins-relative-to标志来更改解析插件的目录。

例如,在您的情况下:

eslint . --resolve-plugins-relative-to=/usr/lib/

或者您可以尝试动态获取路径

# Yarn
eslint . --resolve-plugins-relative-to=$(yarn global dir)

# npm
eslint . --resolve-plugins-relative-to=$(npm root -g)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM