/ / No puedo importar más PouchDB en mi proyecto - node.js, typescript, pouchdb, typescript-typings

No puedo importar más PouchDB en mi proyecto: node.js, typescript, pouchdb, typescript-typings

Estoy trabajando en un proyecto y recientemente PouchDB decidió dejar de trabajar. No puedo compilarlo más en mi proyecto ts. Intenté:

import * as PouchDB from "pouchdb";

export default PouchDB.defaults({
prefix: `http://admin:password@localhost:5984/`
})

pero me sale

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

Si lo intento:

import {PouchDB} from "pouchdb";

export default PouchDB.defaults({
prefix: `http://admin:password@localhost:5984/`
} as any)

yo obtengo

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

Si lo intento:

import PouchDB from "pouchdb";

export default PouchDB.defaults({
prefix: `http://admin:password@localhost:5984/`
} as any)

Luego se compilará pero obtengo esto cuando lo ejecuto:

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

Si lo intento:

 const PouchDB = require("pouchdb");

Pierdo cada mecanografía, así que se convierte en un any tipo que obviamente no quiero

❯ npm ls pouchdb @types/pouchdb
compactd@0.0.0 /mnt/c/Users/Vincent/Documents/GitHub/compactd
├── @types/pouchdb@6.3.0
└── pouchdb@6.3.4

Lo único que hice antes de que dejara de funcionarestaba limpiando node_modules y reinstalando usando npm en lugar de yarn (yarn quiere recompilar todos mis módulos nativos cada vez que instalo algo pero siento que npm está haciendo lo mismo)

Intenté degradar PouchDB a 6.2.0, he intentado todo lo que me está volviendo loco, cualquier ayuda sería realmente apreciada.

Usando ts-node, traté de requerir / importar PouchDB de todas las maneras posibles:

> 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)

Respuestas

0 para la respuesta № 1

A partir de ahora, la mejor solución es:

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

Esto es rápido y sucio, pero la solución real debe ser realizada por el mantenedor de pouchDB