How to import Lodash in Ionic 3?

How can I import Lodash in Ionic 3?
I’ve been trying for hours but nothing seems to work.

import * as _ from 'lodash';

and use it like

 let names = _.map(values, 'Name'),
2 Likes

[11:01:06] typescript: C:/Users/smartguide/Desktop/ionic/Drivers/src/app/app.module.ts, line: 44
Argument of type ‘{ declarations: (typeof ConfirmPage | typeof LoginPage | typeof SignupPage | typeof
AboutPage | t…’ is not assignable to parameter of type ‘NgModule’. Types of property ‘imports’ are
incompatible. Type ‘(ModuleWithProviders | typeof FormsModule | typeof BrowserModule | LoDashStatic)[]’ is
not assignable to type ‘(any[] | Type | ModuleWithProviders)[]’. Type ‘ModuleWithProviders | typeof
FormsModule | typeof BrowserModule | LoDashStatic’ is not assignable to type ‘any[] | Type |
ModuleWithProviders’. Type ‘LoDashStatic’ is not assignable to type ‘any[] | Type |
ModuleWithProviders’. Type ‘LoDashStatic’ is not assignable to type ‘ModuleWithProviders’. Property
’ngModule’ is missing in type ‘LoDashStatic’.

  L44:  @NgModule({                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
  L45:    declarations: [

This is the error I get when importing it the way you did it @FnnHuman.
I get the error when importing * as _ in app.module.ts and when putting it in imports: [ ].

This worked for me:
npm install lodash --save
npm install @types/lodash --save

1 Like

Already tried that, it didn’t work.

1 Like

You don’t need to put it in imports, afaik?

Edit: Tested, works fine without

Thanks @FnnHuman. It worked for me.