cordova - Ionic 2 构建提示无法模块 lodash

标签 cordova angular gulp ionic2 typescript1.8

我使用的是 Ionic v2,每次运行 ionic build android 时都会看到以下错误。

TypeScript error: /path/to/project/app/models/models.ts(1,20): Error TS2307: Cannot find module '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/[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]

最佳答案

我根据 this answer 计算出来的。无论出于何种原因,编译器都会提示,因为它找不到 lodash 的类型定义(在我的例子中是 jquery)。

为了解决这个问题,我只是在我的输入中添加了一个三斜杠引用作为我的 app.ts 文件的第一行:

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

所有错误都消失了。

关于cordova - Ionic 2 构建提示无法模块 lodash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38138295/

相关文章:

android - 库版本之间的 Cordova Android 冲突

Angular ngFor 和分表到标题部分

css - SCSS : how to actually include the contents of a @include?

node.js - 我无法启动服务器-jekyll

iphone - 在 Phonegap + IOS 按钮中使用 iScroll 4 多次触发点击事件

ios - "No code signing identities found"为 iOS 设备构建 cordova 应用程序时出错

javascript - app.receivedEvent 不是一个函数

javascript - RxJS 5, Angular : How to do a request every x seconds UNTIL a message matches a certain string?

angular - angular2-in-memory-web-api 如何为 PUT 方法构造 url?

node.js - 模板路径中的通配符在带有 gulp 的 nunjucks 中不起作用