【问题标题】:following lodash error on build 'Cannot find name 'Exclude''在构建'找不到名称'排除''时出现lodash错误
【发布时间】:2019-07-27 20:33:19
【问题描述】:

我收到以下 lodash 错误

node_modules/@types/lodash/common/object.d.ts(1689,12) 中的错误:错误 TS2304:找不到名称“排除”。 node_modules/@types/lodash/common/object.d.ts(1766,12):错误 TS2304: 找不到名称“排除”。 node_modules/@types/lodash/common/object.d.ts(1842,34):错误 TS2304: 找不到名称“排除”。

【问题讨论】:

  • 请分享 package.json 代码了解您的问题
  • "typescript": "~2.7.2", "@types/lodash": "^4.14.122", "lodash": "^4.17.10", "@angular/cdk" : "^6.4.2", "@angular/cli": "~6.0.8",

标签: angular typescript lodash


【解决方案1】:

解决方案 1
我也遇到了同样的问题,我尝试降级 typescript 版本和 lodash 版本,但没有任何效果,最后我尝试安装 @types/lodash,它成功了。 试试这个:

npm i @types/lodash

希望对你有帮助。

如果上述解决方案不起作用,请尝试以下操作:

解决方案 2
实际问题是,Exclude 已添加到 2.8 版的打字稿中。你可能有一个需要最低 typescript 2.8 的 @types/lodash 版本,如果你的 lodash 和 typescript 版本不匹配,就会发生这种情况。

因此,使用此代码安装与 lodash 兼容的最后一个 typescript 2.3 版本:

npm i -D @types/lodash@ts2.3

【讨论】:

  • 这个解决方案解决了我的问题。谢谢老兄
【解决方案2】:

我今天早上面临同样的问题。 对我来说一种可能的解决方案是修复 package.json 中的 lodash 版本:

"lodash": "^4.17.4" => "lodash": "4.17.4"

"@types/lodash": "^4.14.55" => "@types/lodash": "4.14.55"

并等待更稳定的修复/解决方案。

希望对你有用

【讨论】:

    【解决方案3】:

    最近有关于 lodash 类型的更新 参考:https://www.npmjs.com/package/@types/lodash 最后更新时间:2019 年 3 月 4 日星期一 22:42:42 GMT

    更改"@types/lodash": "4.14.121" 对我有用,因为这是最近更新之前提到的最稳定的版本。

    希望这会有所帮助。

    【讨论】:

      【解决方案4】:

      我今晚也遇到同样的错误。我尝试重新安装所有这些,但没有任何反应。

      我现在使用的:

      打字稿:2.2.2 - 离子:3,离子 CLI:4.1.2 - 科尔多瓦:8.1.2 - 角 CLI:1.2.4

      我现在的解决方案:将 typesript 版本设置为 3.2.4 => 它对我有用

      更新 现在,我通过强制安装 lodash 来解决问题:npm install --save @types/lodash@4.14.118

      【讨论】:

        【解决方案5】:

        我间接解决了这个问题。

        1. package-lock.json 中查找@types/lodash

        2. 更新package.json

        【讨论】:

        【解决方案6】:

        我 2 天后出现同样的错误。

        我的 package.json:

        {
          "name": "my-app",
          "version": "0.0.0",
          "license": "MIT",
          "scripts": {
            "ng": "ng",
            "start": "ng serve",
            "build": "ng build",
            "prod": "ng build --prod",
            "test": "ng test",
            "lint": "ng lint",
            "e2e": "ng e2e"
          },
          "private": true,
          "dependencies": {
            "@angular/animations": "^4.1.1",
            "@angular/common": "^4.0.1",
            "@angular/compiler": "^4.0.1",
            "@angular/core": "^4.0.1",
            "@angular/forms": "^4.0.1",
            "@angular/http": "^4.0.1",
            "@angular/platform-browser": "^4.0.1",
            "@angular/platform-browser-dynamic": "^4.0.1",
            "@angular/router": "^4.0.1",
            "angular2-json-schema-form": "https://github.com/ptv-ldts/angular2-json-schema-form/tarball/impact?v1.0.2",
            "angular2-notifications": "^0.7.3",
            "bootstrap": "^3.3.7",
            "clipboard": "^1.6.1",
            "core-js": "^2.4.1",
            "gulp": "^3.9.1",
            "gulp-cheerio": "^0.6.2",
            "gulp-clean": "^0.3.2",
            "gulp-rename": "^1.2.2",
            "lodash": "^4.17.4",
            "ng2-ace-editor": "^0.1.9",
            "ng2-bs3-modal": "^0.10.4",
            "ng2-smart-table": "1.2.1",
            "ngx-clipboard": "^5.1.0",
            "zone.js": "^0.8.4"
          },
          "devDependencies": {
            "@angular/cli": "1.0.0",
            "@angular/compiler-cli": "^4.0.1",
            "@types/jasmine": "2.5.38",
            "@types/lodash": "^4.14.55",
            "@types/node": "~6.0.60",
            "angular-ide": "^0.9.19",
            "codelyzer": "~2.0.0",
            "jasmine-core": "~2.5.2",
            "jasmine-spec-reporter": "~3.2.0",
            "jquery": "^3.2.1",
            "json-loader": "^0.5.4",
            "karma": "~1.4.1",
            "karma-chrome-launcher": "~2.0.0",
            "karma-cli": "~1.0.1",
            "karma-coverage": "^1.1.1",
            "karma-coverage-istanbul-reporter": "^0.2.0",
            "karma-jasmine": "~1.1.0",
            "karma-jasmine-html-reporter": "^0.2.2",
            "karma-junit-reporter": "^1.2.0",
            "karma-phantomjs-launcher": "^1.0.4",
            "protractor": "~5.1.0",
            "ts-node": "~2.0.0",
            "tslint": "~4.5.0",
            "typescript": "~2.2.0"
          },
          "peerDependencies": {
            "rxjs": "^5.1.0"
          }
        }
        

        更新: 我发现的是,排除在 typescript 2.8 中。我将 json 包中 typescript 的行更改为 "typescript": "^2.2.0" 并更新。

        【讨论】:

        • 你的“更新”是什么意思?我在pakage.json里改了行但是还是不行,是不是需要运行命令才能生效?
        【解决方案7】:

        我们遇到了这个问题,我们不得不将 typescript 版本增加到“2.8”来解决“排除”错误。

        注意:确保使用您的 @angular/cli 版本所需的 typescript 版本。

        比如,在我的情况下,@angluar/cli 版本是“6.0.8”,它可以接受 typescript 版本“2.8”。

        【讨论】:

          【解决方案8】:

          对我来说,这似乎是 lodash 从 4.14.118 -> 4.14.122 的变化。在 4.14.118 中修复修复了此问题。

          "@types/lodash": "4.14.118",

          【讨论】:

            【解决方案9】:

            在我的例子中,我不得不将 angular-tree-component 从 7.2.0 更新到 8.2.0 并且问题得到了解决!

            【讨论】:

              【解决方案10】:

              我们也遇到过同样的问题,但是在我将 package.json 文件中的 lodash 版本从 - "@types/lodash": "^4.14.111" 更改为 "@types/lodash": "4.14.121" 后问题得到了解决

              【讨论】:

                【解决方案11】:

                我遇到了同样的问题。 我通过使用以下命令安装 lodash 解决了这个问题

                npm install --save @types/lodash@4.14.55

                查看Package.json中提到的版本,安装对应版本即可解决问题。

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 2020-03-27
                  • 2019-09-17
                  • 2020-12-21
                  • 2020-06-22
                  • 2015-07-07
                  • 2022-11-10
                  • 2014-03-04
                  • 1970-01-01
                  相关资源
                  最近更新 更多