2

I'm trying to import lodash into a file in Angular2 with TypeScript built with Webpack. I always get an error Cannot find module 'lodash' or Cannot find module 'lodash/submodule'. However, the code still works properly and in fact if I don't do the import the code does not work properly.

import * as lodash from "lodash";
export class SomeService {
  fn(): any {
    return lodash.range(1, 2);
  }
}

This works properly, but I still get the Cannot find module error. I've also tried with import lodash from "lodash", import {range} from "lodash" and import * as range from "lodash/range" among a few other things, but no matter what, I always get this error.

I've done yarn add lodash and typings install lodash. node_modules/lodash exists and has node_ modules/lodash/range.js exist. In fact, import * as moment from "moment" seems to be working fine.

Is there any way to get TypeScript to stop reporting this as an error?

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • 3
    Using TS 2.0? [Try this](http://stackoverflow.com/questions/34660265/importing-lodash-into-angular2-typescript-application). `@types/lodash` contains the types now. – Tholle Oct 25 '16 at 22:15

1 Answers1

2

You should install the @types/lodash package via: npm install --save @types/lodash

Allan
  • 27
  • 5