我在Ionic v2上,每次运行 ionic build android
时都会看到以下错误 .
TypeScript错误:/ path/to/project/app/models/models.ts(1,20):错误TS2307:找不到模块'lodash' .
看到这个错误,我确实没有任何副作用 . 例如,我的移动应用程序在浏览器,模拟器和设备中运行良好 . 但是,我想知道如何摆脱这个错误 .
当我添加 lodash
时,我必须输入以下命令 .
npm install lodash --save
typings install lodash --save
ionic info
给了我以下内容 .
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
有关我的开发工具版本的其他信息 .
-
节点4.3.1
-
npm 3.8.6
-
gulp CLI 1.2.1,本地3.9.1
-
cordova 6.2.0
-
凉亭1.7.9
-
tsc 1.8.10
运行 npm list --depth=0
以下是我的依赖项 .
├── @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 回答
我根据this answer想出来了 . 无论出于何种原因,编译器都会抱怨,因为它找不到
lodash
的类型定义(在我的例子中是jquery
) .为了解决这个问题,我在我的
app.ts
文件的第一行添加了一个对我的打字的三斜杠引用:所有的错误都消失了 .