Angular 2 / Angular 2 CLI / lodash 函数未找到

Angular 2 / Angular 2 CLI / lodash functions not found

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 使用:-

import * as _ from 'lodash';

编译的 scripts.bundle.js 包含 lodash javascript。

有什么我忘了的吗?

谢谢!

编辑不要添加到您的 angular-cli.json 文件脚本部分。这不需要!

你似乎就在那里,只是为了确保,这里是我如何在我的一个项目中重现它的步骤:

  • 停止当前ng serve
  • npm install lodash --savenpm install @types/lodash --save-dev
  • 在控制器中做你的import * as _ from 'lodash';
  • 这样使用:console.log(_.chunk(['a', 'b', 'c', 'd'], 2));
  • ng serve