2

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 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

The problem was putting it in the angular-cli.json. I have been trying to fix this for a day (it was previously working - I think when I did an npm install some of the package versions were upped, now it no longer works with lodash in the scripts section). Could you elaborate on why it's not needed in the scripts section? Thanks for your help, you saved my sanity! :)
I am no export on this but I understand adding it to the scrips section will add the js-library to the global scope of your angular app. This is not neeed with lodash. Usually a simple npm install and then import should be all it needs now that angular-cli uses webpack and not systemjs anymore. (See github.com/angular/angular-cli#3rd-party-library-installation) Glad you got it working

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.