typescript 在构建“无法找到名称“排除”时出现以下 lodash 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/55018665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
following lodash error on build 'Cannot find name 'Exclude''
提问by Rajesh Reddy
I am getting following lodash error
我收到以下 lodash 错误
ERROR in node_modules/@types/lodash/common/object.d.ts(1689,12): error TS2304: Cannot find name 'Exclude'. node_modules/@types/lodash/common/object.d.ts(1766,12): error TS2304: Cannot find name 'Exclude'. node_modules/@types/lodash/common/object.d.ts(1842,34): error TS2304: Cannot find name 'Exclude'.
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:找不到名称“排除”。
回答by Gaius
Solution 1
I also had the same issue, i tried to downgrade typescript version and lodash version, but nothing worked, and at last i tried installing @types/lodash, and it worked.
just try this:
解决方案 1
我也遇到了同样的问题,我尝试降级 typescript 版本和 lodash 版本,但没有任何效果,最后我尝试安装 @types/lodash,并且成功了。试试这个:
npm i @types/lodash
hope it helps.
希望能帮助到你。
If the above solution doesn't work try this:
Solution 2
The actual issue is, Exclude was added to typescript on version 2.8. You might have a version of @types/lodash that needs minimum typescript 2.8, and it can happen if your lodash and typescript version didn't match.
如果上述解决方案不起作用,请尝试以下操作:
解决方案 2
实际问题是,排除已添加到 2.8 版的打字稿中。您可能有一个需要最低 typescript 2.8 的 @types/lodash 版本,如果您的 lodash 和 typescript 版本不匹配,就会发生这种情况。
So, install the last typescript 2.3 version compatible with lodash using this code :
因此,使用以下代码安装与 lodash 兼容的最新 typescript 2.3 版本:
npm i -D @types/[email protected]
回答by Ish
There are recent updates on lodash typings reference : https://www.npmjs.com/package/@types/lodashLast updated: Mon, 04 Mar 2019 22:42:42 GMT
有关于 lodash 类型参考的 最新更新:https: //www.npmjs.com/package/@types/lodash最后更新:2019 年 3 月 4 日星期一 22:42:42 GMT
changing "@types/lodash": "4.14.121"
worked for me as this was the most stable version referred prior to recent update.
更改"@types/lodash": "4.14.121"
对我有用,因为这是最近更新之前提到的最稳定的版本。
Hope this helps.
希望这可以帮助。
回答by Yuan
I'm facing the same issue this morning. One possible solution for me is to fix the lodash version in the package.json :
我今天早上面临同样的问题。对我来说,一种可能的解决方案是修复 package.json 中的 lodash 版本:
"lodash": "^4.17.4"
=> "lodash": "4.17.4"
"lodash": "^4.17.4"
=> "lodash": "4.17.4"
"@types/lodash": "^4.14.55"
=> "@types/lodash": "4.14.55"
"@types/lodash": "^4.14.55"
=> "@types/lodash": "4.14.55"
And waiting for a more stable fix/solution.
并等待更稳定的修复/解决方案。
Hope that works for you
希望对你有用
回答by lehieusoftware
I have the same error for this evening. I try to re-install all of them but nothing happend.
今天晚上我有同样的错误。我尝试重新安装所有这些,但什么也没发生。
Current I use:
目前我使用:
Typescript: 2.2.2 - Ionic: 3, Ionic CLI: 4.1.2 - Cordova: 8.1.2 - Angular CLI: 1.2.4
打字稿:2.2.2 - Ionic:3,Ionic CLI:4.1.2 - Cordova:8.1.2 - Angular CLI:1.2.4
My solution for now: Set the typesript version to 3.2.4 => It work for me
我现在的解决方案:将 typeript 版本设置为 3.2.4 => 它对我有用
UpdatedFor now, I fix issue by force install the lodash: npm install --save @types/[email protected]
更新现在,我通过强制安装 lodash 来解决问题:npm install --save @types/[email protected]
回答by poootta
I solved this problem indirectly.
我间接解决了这个问题。
Find
@types/lodash
inpackage-lock.json
Update
package.json
查找
@types/lodash
中package-lock.json
更新
package.json
回答by Kalyan
We faced this issue and we had to increment the typescript version to "2.8" to solve the "Exclude" error.
我们遇到了这个问题,我们不得不将打字稿版本增加到“2.8”以解决“排除”错误。
Note: Make sure to use the typescript version which is required by your @angular/cli version.
注意:确保使用 @angular/cli 版本所需的打字稿版本。
Like, in my case @angluar/cli version is "6.0.8" which can accept typescript version "2.8".
就像,在我的情况下,@angluar/cli 版本是“6.0.8”,它可以接受打字稿版本“2.8”。
回答by Tirinoarim
For me, it appeared to be a change of lodash from 4.14.118 -> 4.14.122. Fixing at 4.14.118 fixed this issue.
对我来说,这似乎是 lodash 从 4.14.118 -> 4.14.122 的变化。在 4.14.118 修复修复了这个问题。
"@types/lodash": "4.14.118",
"@types/lodash": "4.14.118",
回答by MTA
I have the same error since 2 days.
自 2 天以来我有同样的错误。
my package.json:
我的 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"
}
}
Update: What I found was, that exclude comes in with typescript 2.8. I changed the line in package json for typescript to "typescript": "^2.2.0" and updated.
更新:我发现的是,那个排除来自打字稿 2.8。我将 typescript 包 json 中的行更改为 "typescript": "^2.2.0" 并更新。
回答by aryan2312
We have faced the same issue but it got resolved after I change the version of lodash from - "@types/lodash": "^4.14.111"
to "@types/lodash": "4.14.121"
in the package.json file
我们都面临着同样的问题,但在我改变lodash的版本,从它得到了解决-"@types/lodash": "^4.14.111"
以 "@types/lodash": "4.14.121"
中的package.json文件
回答by Aishwarya Ramesh
In my case, I had to update angular-tree-component from 7.2.0 to 8.2.0 and the problem got resolved!
就我而言,我不得不将 angular-tree-component 从 7.2.0 更新到 8.2.0,问题得到解决!