【问题标题】:angular2 error in lodash jslodash js中的angular2错误
【发布时间】:2017-06-27 09:12:24
【问题描述】:

我尝试将 lodash 用于数据表。这是我尝试过的:

  • npm install lodash - 出现找不到包错误

  • 搜索问题,然后尝试 npm install --save @types/lodash

这产生了以下输出:

+-- UNMET DEPENDENCY @angular/common@~2.1.0
+-- UNMET PEER DEPENDENCY @angular/compiler@2.4.6 invalid
+-- UNMET DEPENDENCY @angular/core@~2.1.0
`-- @types/lodash@4.14.52

我不明白,因为我的 package.json 有以下内容:

"@angular/common": "~2.1.0",
"@angular/compiler": "~2.1.0",
"@angular/core": "~2.1.0",
  • 在此之后,IDE 可以找到包,但是当我运行 npm start/ng serve 时出现多个错误

    [默认] 路径\node_modules\@types\lodash\index.d.ts:192中的错误 81:20 找不到命名空间“_”。

    [默认] 路径\node_modules\@types\lodash\index.d.ts:190中的错误 21:57 找不到名称“许多”。

    [默认] 路径\node_modules\@types\lodash\index.d.ts:194中的错误 41:0 需要声明或声明。

前两个错误每​​个重复多次,但数字不同(我猜是行)

我应该怎么做才能解决这个问题?

【问题讨论】:

    标签: node.js angular npm lodash


    【解决方案1】:

    当您安装旧模块(如 package.json 中所写)但由于版本更新而在 git 上不可用时,会出现此问题。 解决这个问题

        1.Need to install the project’s local dependencies (that’s where it’s looking for lodash). To do that,
        2.cd into the project directory and run npm install.
        3.You can also try npm i --save lodash
    

    如果 package.json 文件存在,并且它包含 lodash 依赖项,您可以尝试删除 node_modules 文件夹并运行以下命令:

    $ npm cache clean    
    $ npm install
    

    第一个命令将清理 npm 缓存。 (只是为了确定)第二个命令将安装项目的所有(缺少的)依赖项。

    【讨论】:

      【解决方案2】:

      所以对我有用的是从另一个(工作项目)获取 package.json 文件并运行 npm install。我仍然不知道为什么我的不起作用,但这就是解决问题的方法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-10-18
        • 1970-01-01
        • 2018-03-13
        • 2017-11-05
        • 2016-05-09
        • 2016-08-04
        • 2014-05-09
        • 1970-01-01
        相关资源
        最近更新 更多