2017-09-26 65 views
1

我正在開發一個項目,最近PouchDB決定停止工作。我不能在我的ts項目中編譯它。我想:無法在我的項目中導入PouchDB

import * as PouchDB from 'pouchdb'; 

export default PouchDB.defaults({ 
    prefix: `http://admin:[email protected]:5984/` 
}) 

,但我得到

server/src/database.ts(3,24): error TS2339: Property 'defaults' does not exist on type 'typeof 'pouchdb''. 

如果我嘗試:

import {PouchDB} from 'pouchdb'; 

export default PouchDB.defaults({ 
    prefix: `http://admin:[email protected]:5984/` 
} as any) 

我得到

server/src/database.ts(1,9): error TS2305: Module ''pouchdb'' has no exported member 'PouchDB'. 

如果我嘗試:

import PouchDB from 'pouchdb'; 

export default PouchDB.defaults({ 
    prefix: `http://admin:[email protected]:5984/` 
} as any) 

然後,它會編譯,但我得到這個當我運行它:

export default PouchDB.defaults({ 
        ^
TypeError: Cannot read property 'defaults' of undefined 
    at Object.<anonymous> ... 

如果我嘗試:

const PouchDB = require('pouchdb'); 

我失去了所有的類型,所以就變成了any型我OBV不想要

❯ npm ls pouchdb @types/pouchdb 
[email protected] /mnt/c/Users/Vincent/Documents/GitHub/compactd 
├── @types/[email protected] 
└── [email protected] 

我停止工作之前做的唯一事情是清理node_modules並重新啓動所有使用npm而不是紗線(紗線希望重新編譯所有我的本地模塊,每次我安裝的東西,但我覺得npm是這樣做的)

我試着降級PouchDB到6.2.0,我瘋狂的任何幫助將非常感激。

使用TS-節點,我試圖要求/進口PouchDB一切可能的方式:

> require('pouchdb') 
{ [Function: PouchDB$5] 
    super_: 
    { [Function: AbstractPouchDB] 
    super_: 
     { [Function: EventEmitter] 
     EventEmitter: [Object], 
     usingDomains: true, 
     defaultMaxListeners: [Getter/Setter], 
     init: [Function], 
     listenerCount: [Function] } }, 
    adapters:... 

> import PouchDB from 'pouchdb' 
undefined 
> PouchDB 
undefined 

> import * as PouchDB from 'pouchdb' 
[eval].ts:2 
Object.defineProperty(exports, "__esModule", { value: true }); 
        ^

ReferenceError: exports is not defined 
    at [eval].ts:2:23 
    at ContextifyScript.Script.runInContext (vm.js:53:29) 
    at ContextifyScript.Script.runInNewContext (vm.js:59:15) 
    at _eval (/home/vincent/.nvm/versions/node/v8.5.0/lib/node_modules/ts-node/dist/_bin.js:181:29) 
    at REPLServer.replEval (/home/vincent/.nvm/versions/node/v8.5.0/lib/node_modules/ts-node/dist/_bin.js:220:18) 
    at bound (domain.js:301:14) 
    at REPLServer.runBound [as eval] (domain.js:314:12) 
    at REPLServer.onLine (repl.js:440:10) 
    at emitOne (events.js:115:13) 
    at REPLServer.emit (events.js:210:7) 

> import {PouchDB} from 'pouchdb' 
Thrown: ⨯ Unable to compile TypeScript 
[eval].ts (1,9): Module ''pouchdb'' has no exported member 'PouchDB'. (2305) 
+0

我的猜測是你的node_modules文件夾中有一個PouchDB的舊版本,並且它的界面已更改。也許嘗試在'node'或'ts-node' REPL中導入(或要求)該模塊?然後,您可以記錄您的PouchDB對象,並查看其上可用的屬性。如果你的類型定義不匹配,這不會解決問題,但也許它可以幫助找到排隊的PouchDB和@ types/PouchDB版本 –

+0

@NathanWilson調試了很多之後,我發現我想要的定義在自6.0.5以來的'pouchdb/lib/index.es'中。當然,我不能直接導入.es文件,沒有發現類型。試圖安裝6.0.4現在... – Vinz243

+0

Nvm,仍然無法使用6.0.4 ... – Vinz243

回答

0

截至目前,最好的解決方法是:

import Pouch from 'pouchdb'; 
const PouchDB: typeof Pouch = require('pouchdb'); 

這是快速和骯髒的,但真正的修復需要由pouchDB維護人員完成