找不到Angular 2/Angular 2 CLI/lodash函数 [英] Angular 2 / Angular 2 CLI / lodash functions not found

查看:70
本文介绍了找不到Angular 2/Angular 2 CLI/lodash函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们收到有关angular-cli beta 18的错误

We are getting the error with angular-cli beta 18

Error: Uncaught (in promise): TypeError: __WEBPACK_IMPORTED_MODULE_6_lodash__.find is not a function

Lodash +类型已添加到package.json:-

Lodash + Types were added to the package.json: -

"lodash": "4.14",
"@types/lodash": "4.14.38",

在angular-cli.json的脚本部分中,我们对模块进行了引用

In the scripts section of angular-cli.json we have a reference to the module

"../node_modules/lodash/lodash.js",

我们正在使用以下方法导入lodash:-

We are importing lodash using: -

import * as _ from 'lodash';

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

The compiled scripts.bundle.js has the lodash javascript included.

有什么我忘记的东西吗?

Is there anything I have forgotten about?

谢谢!

推荐答案

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

您似乎已经准备好了,只是为了确保,这是我如何在我的一个项目中进行复制的步骤:

You seem to have it right there, just to make sure, here are the steps with how i can reproduce it working on one of my projects:

  • 停止当前的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
  • stop the current ng serve
  • do npm install lodash --save and npm install @types/lodash --save-dev
  • In the controler do your import * as _ from 'lodash';
  • Use it like this: console.log(_.chunk(['a', 'b', 'c', 'd'], 2));
  • ng serve again

这篇关于找不到Angular 2/Angular 2 CLI/lodash函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆