Reputation: 45
I am trying to install pouchdb in a typescript (ionic) application. The types don't work
npm install --save pouchdb
npm install --save-dev @types/pouchdb
When I try to use it (import Pouchdb from 'pouchdb'), I get this error
ERROR in src/app/services/pouchdb.service.ts(3,8): error TS1192: Module '"C:/Users/User/PROG/toto/node_modules/@types/pouchdb/index"' has no default export.
I tried
import * as Pouchdb from 'pouchdb'
The error disappears here, but appears after, I still can't use the pouchdb functions.
Is there a solution?
Upvotes: 3
Views: 1801
Reputation: 451
I also am using Ionic 4, PouchDB and pouchdb-find. The following worked for me:
npm install pouchdb @types/pouchdb
npm install pouchdb-find @types/pouchdb-find
In tsconfig.json I added the following:
{
{
"compilerOptions": {
"allowSyntheticDefaultImports": true
}
}
Then in the provider where I'm using pouchdb and pouchdb-find, I put the following 2 lines:
const PouchDB = require('pouchdb');
PouchDB.plugin(require('pouchdb-find'));
Upvotes: 0
Reputation: 614
Have you seen this? https://pouchdb.com/guides/setup-pouchdb.html#typescript
In tsconfig.json
:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true
}
}
Then in TypeScript:
import PouchDB from 'pouchdb';
Upvotes: 3
Reputation: 16
const PouchDB = require('pouchdb').default;
This worked for me.
Upvotes: 0