【问题标题】:Typescript can't find 'require', setting up pouchdb with Ionic2Typescript 找不到“require”,使用 Ionic2 设置 pouchdb
【发布时间】:2017-06-08 00:31:28
【问题描述】:

我也在尝试遵循教程 How To Use PouchDB + SQLite For Local Storage In Ionic 2,这似乎是使用 pouchdb 和 Angular 2 / Ionic 2 的一个很好的切入点。我的操作系统是 OSx

在能够安装类型后'require'ionic serve throws:

TypeScript error: (...) Error TS2304: Cannot find name 'require'.

我关注了installing typings require failed in macOSXInstall Typings require for Ionic2 application 线程,但这对我没有帮助。 (除了更好地理解“TypeScript”之外)

需要的文件位于:

/ionic2-tutorial-pouchdb/typings/globals/require

有什么想法吗?关于“安装要求”的教程对我不起作用。

谢谢皮特

【问题讨论】:

  • 感谢@devid-farinelli 改进我的帖子...

标签: angularjs typescript ionic-framework pouchdb


【解决方案1】:

我猜你有这样一行代码:

let PouchDB = require('pouchdb');

你不需要使用 require 来导入 Angular2。相反,您应该像这样使用导入:

import PouchDB from 'pouchdb';

Reference from one of the GitHub issues on the PouchDB GitHub account

您提供的链接也使用 import 而不是 require。同样在较新版本的 typescript 中,Typings 已替换为 @Types。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-01
    • 2016-09-15
    • 1970-01-01
    • 2016-06-08
    • 2018-01-28
    • 1970-01-01
    • 2013-12-11
    相关资源
    最近更新 更多