Search code examples
angularlodashangular2-cli

Angular 2 / Angular 2 CLI / lodash functions not found


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!


Solution

  • 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