3

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?

1
  • 3
    Using TS 2.0? Try this. @types/lodash contains the types now. Commented Oct 25, 2016 at 22:15

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.