我正在尝试使用Typescript和PouchDB。但是我无法链接到PouchDB模块。
import { PouchDB } from "pouchdb"
报告显示它找不到pouchdb模块,尽管它在node_modules中。我也找不到适当的pouchdb typings。
我正在尝试使用Typescript和PouchDB。但是我无法链接到PouchDB模块。
import { PouchDB } from "pouchdb"
我正在使用Ionic进行操作,因此可能会在正确加载类型文件方面漏掉一步。
请确保已安装您的类型:
npm install --save-dev @types/pouchdb
在导入数据服务的文件中,将其放置在pouch的顶部位置:
import * as PouchDB from 'pouchdb';
*编辑*
虽然我不了解所有的事实,但这是我目前的理解: 在TypeScript>2.0中,不再需要使用Typings。 我相信TypeScript现在会自动处理从DefinitelyTyped安装的类型文件。 DefinitelyTyped是一个官方的中央仓库,像npm一样保持最新。 即使我完全错了,DefinitelyTyped仍然比typings更好,并且有着更庞大的社区。
ng new SOMENAME
npm install --save pouchdb
npm install --save-dev @types/pouchdb
import PouchDB from 'pouchdb';
public db: any;
并初始化this.db = new PouchDB('test'); // , {storage:'persistent'} not working in typescript without updating typings
npm install --save pouchdb --no-optional
禁用警告。安装仍应正常进行。有关更多信息,请参见https://github.com/npm/npm/issues/17671。我遇到了同样的问题,尝试将其导入到Angular 6中。
您的导入看起来很好:
import PouchDB from 'pouchdb';
import PouchFind from 'pouchdb-find';
PouchDB.plugin(PouchFind);
polyfills.ts
文件中添加以下内容:(window as any).global = window;
(window as any).process = {};
(window as any).process.nextTick = setTimeout;
我通过使用以下方法成功地使模块被识别
declare function require(a)
var PouchDB = require("pouchdb")
我已经放弃了类型检查,但至少我可以取得进展。