找不到模块'eslint-plugin-angular' [英] Cannot find module 'eslint-plugin-angular'

查看:169
本文介绍了找不到模块'eslint-plugin-angular'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将ESLint集成到我的项目中,并且遇到错误:在运行时找不到模块'eslint-plugin-angular' $ eslint * .js

I'm trying to integrate ESLint into my project and I'm running into the error: "Cannot find module 'eslint-plugin-angular'" when I run $ eslint *.js.

我可以运行此方法的唯一方法是在全局安装eslint-plugin-angular,但这似乎错误(除非我错过了什么?)。

The only way I can get this to run is by installing eslint-plugin-angular globally, but that seems wrong (unless I'm missing something??).

我正在运行:


  • 节点v0.12.7

  • npm 3.3.4

  • eslint v1.5.0

  • eslint -plugin-angular 0.12.0

  • node v0.12.7
  • npm 3.3.4
  • eslint v1.5.0
  • eslint-plugin-angular 0.12.0

ESLint已全局安装。

ESLint is installed globally.

我的 package.json 文件包含以下条目:

My package.json file has the following entries:


  • eslint: ^ 1.5.0,

  • eslint-plugin-angular: ^ 0.12.0,

我有 $ rm -rf node_modules 并重新运行 $ npm install 以确保没有某种npm依赖性问题或损坏。我还验证了 node_modules 中的目录权限,以确保可以访问。

I have $ rm -rf node_modules and rerun $ npm install to make sure there wasn't some kind of npm dependency issue or corruption. I also verified the directory permissions in node_modules to make sure access is possible.

我的 .eslintrc 包含:

{
    "plugins": [
        "angular"
    ],
    "rules": {
    "angular/ng_controller_name": [
        2,
        "/[A-Z].*Controller$/"
    ],
    "quotes": [
        2,
        "single"
    ]
    },
        "globals": {
        "angular": true
    }
}

我在这里缺少什么?谢谢!
ps。我确实在github上打开了一张票: https://github.com/Gillespie59/eslint -plugin-angular / issues / 222 -只是想知道Stack社区中是否有人遇到过这种情况。

What am I missing here? Thx! ps. I did open a ticket on github: https://github.com/Gillespie59/eslint-plugin-angular/issues/222 -- just wondering if someone in the Stack community has run into this.

推荐答案

在此处找到答案: http://eslint.org/docs/user- guide / configuring#configuring-plugins

注意:全局安装的ESLint实例只能使用全局安装的ESLint插件。本地安装的ESLint可以确保本地和全局安装的ESLint插件都可以。

"Note: A globally-installed instance of ESLint can only use globally-installed ESLint plugins. A locally-installed ESLint can make sure of both locally- and globally- installed ESLint plugins."

请仔细阅读文档中的详细说明。 :/

This falls under read the fine print in the documentation. :/

有两种处理方法:

(1)安装插件全球。我并不特别喜欢它,因为我有多个客户端项目位于不同版本的依赖项上,而不必将它们全部都颠簸到同一版本。

(1) Install the plugin(s) globally. I'm not a particular fan of this because I have multiple client projects that are on different versions of dependencies and I can't necessarily just bump them all to the same version.

(2)在本地安装插件并将脚本添加到您的 package.json 文件:

(2) Install the plugin(s) locally and add a script to your package.json file:

{
    ... other stuff
    "scripts": {
        "eslint": "eslint",
        "lint": "eslint. "
    }
    ... other stuff
}

(如果您对此不陌生,请记住, ...其他内容不是您的package.json文件中真正想要的。 ..)

(If you're completely new to this, just keep in mind that ... other stuff isn't what you'd actually want in your package.json file...)

通过此设置,我可以使用 npm run eslint 来使用 eslint ,然后我使用 npm run lint 来实际完成我的项目。

With this setup, I'm able to use npm run eslint to use eslint and I use npm run lint to actually lint my project.

您可以在 scripts 字段的 package.json 文件中找到文档: https://docs.npmjs.com/misc/scripts

You can find documentation on the scripts field for the package.json file here: https://docs.npmjs.com/misc/scripts

这篇关于找不到模块'eslint-plugin-angular'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆