2

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/common@2.0.0-rc.2
├── @angular/compiler@2.0.0-rc.2
├── @angular/core@2.0.0-rc.2
├── @angular/http@2.0.0-rc.2
├── @angular/platform-browser@2.0.0-rc.2
├── @angular/platform-browser-dynamic@2.0.0-rc.2
├── @angular/router@2.0.0-rc.2
├── del@2.2.0
├── es6-shim@0.35.1
├── gulp@3.9.1
├── gulp-watch@4.3.5
├── ionic-angular@2.0.0-beta.8
├── ionic-gulp-browserify-typescript@1.1.0
├── ionic-gulp-fonts-copy@1.0.0
├── ionic-gulp-html-copy@1.0.0
├── ionic-gulp-sass-build@1.0.0
├── ionic-gulp-scripts-copy@2.0.0
├── ionic-native@1.2.4
├── ionicons@3.0.0
├── lodash@4.13.1
├── reflect-metadata@0.1.3
├── run-sequence@1.1.5
├── rxjs@5.0.0-beta.6
└── zone.js@0.6.12
1
  • +1 I have noticed the same issue. Also happens with jquery: TypeScript error: Error TS2307: Cannot find module 'jquery'.
    – morphatic
    Jul 3, 2016 at 3:43

1 Answer 1

2

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.

2
  • I had to modify typings/main.d.ts to add the reference.
    – Jane Wayne
    Jul 4, 2016 at 9:18
  • Part of the problem was that I was on an older version of typings which was generating code in main.d.ts. I then upgraded my typingsand now the references are placed in index.d.ts.
    – Jane Wayne
    Jul 4, 2016 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.