2
votes

I am on Ionic v2, and every time I run ionic build android I see the following error.

TypeScript error: /path/to/project/app/models/models.ts(1,20): Error TS2307: Cannot find module 'lodash'.

There really is no side-effects that I can tell from seeing this error. For example, my mobile application runs fine in the browsers, emulators and devices. However, I'd like to know how to get rid of this error.

When I added lodash I had to type in the following commands.

npm install lodash --save
typings install lodash --save

ionic info gives me the following.

Cordova CLI: 6.2.0
Gulp version:  CLI version 1.2.1
Gulp local:   Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.8
Ionic CLI Version: 2.0.0-beta.32
Ionic App Lib Version: 2.0.0-beta.18
ios-deploy version: 1.8.5 
ios-sim version: 5.0.7 
OS: Mac OS X El Capitan
Node Version: v4.3.1
Xcode version: Xcode 7.3.1 Build version 7D1014

Additional information on my development tool versions.

  • node 4.3.1
  • npm 3.8.6
  • gulp CLI 1.2.1, Local 3.9.1
  • cordova 6.2.0
  • bower 1.7.9
  • tsc 1.8.10

running npm list --depth=0 the following are my dependencies.

├── @angular/[email protected]
├── @angular/[email protected]
├── @angular/[email protected]
├── @angular/[email protected]
├── @angular/[email protected]
├── @angular/[email protected]
├── @angular/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
1
+1 I have noticed the same issue. Also happens with jquery: TypeScript error: Error TS2307: Cannot find module 'jquery'.morphatic

1 Answers

2
votes

I figured it out based on this answer. For whatever reason, the compiler complains because it cannot find the type definitions for lodash (and in my case jquery).

To solve it, I just added a triple-slash reference to my typings as the very first line of my app.ts file:

/// <reference path="../typings/index.d.ts" />

And all of the errors went away.