我们在 angular-cli beta 18 中遇到错误
Error: Uncaught (in promise): TypeError: __WEBPACK_IMPORTED_MODULE_6_lodash__.find is not a function
Lodash + 类型已添加到 package.json:-
"lodash": "4.14",
"@types/lodash": "4.14.38",
在 angular-cli.json 的脚本部分中,我们有对该模块的引用
"../node_modules/lodash/lodash.js",
我们正在使用以下方式导入 lodash:-
从'lodash'导入* as _;
编译后的scripts.bundle.js
包含lodash javascript。
有什么我忘记的事情吗?
谢谢!
最佳答案
编辑: 不要添加到 angular-cli.json 文件脚本部分。这是不需要的!
您似乎已经拥有它,只是为了确保,以下是我如何在我的项目之一中重现它的步骤:
- 停止当前
ng服务
- 执行
npm install lodash --save
和npm install @types/lodash --save-dev
- 在 Controller 中执行
import * as _ from 'lodash';
- 像这样使用它:
console.log(_.chunk(['a', 'b', 'c', 'd'], 2));
再次发球
关于未找到 Angular 2/Angular 2 CLI/lodash 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40379678/