在构建'找不到名称'排除'后出现lodash错误

Raj*_*ddy 8 typescript lodash angular

我正在跟踪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:找不到名称“排除”。

Gai*_*ius 13

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

npm i @types/lodash
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你。

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

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

因此,使用以下代码安装与 lodash 兼容的最新 typescript 2.3 版本:

npm i -D @types/lodash@ts2.3
Run Code Online (Sandbox Code Playgroud)


小智 6

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

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

希望这可以帮助。


小智 5

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

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

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

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

希望对你有用


MTA*_*MTA 1

两天以来我遇到了同样的错误。

我的 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"
  }
}
Run Code Online (Sandbox Code Playgroud)

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