Angular 2 / Angular 2 CLI / lodash functions not found

无人久伴 提交于 2019-12-11 01:56:27

问题


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 + Types were added to the package.json: -

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

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

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

We are importing lodash using: -

import * as _ from 'lodash';

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

Is there anything I have forgotten about?

Thanks!


回答1:


EDIT: Don't add to your angular-cli.json files scripts section. This is not needed!

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:

  • 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


来源:https://stackoverflow.com/questions/40379678/angular-2-angular-2-cli-lodash-functions-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!