Reputation: 21
I'm trying to import PouchDB into my Angular application. I've tested differents import methods :
import PouchDB from 'pouchdb';
import * as PouchDB from 'pouchdb';
I am using it like below into a service :
database: PouchDB.Database = new PouchDB(DATABASE_URL);
If I do : import PouchDB from 'pouchdb'
, I get the following error message :
src/app/core/pouchdb/pouchdb.service.ts(3,8): error TS1192: Module '"{PATH_OF_PROJECT}/node_modules/@types/pouchdb/index"' has no default export.
If I do : import * as PouchDB from 'pouchdb'
, I get the following error message :
ERROR TypeError: PouchDB is not a constructor at new PouchDBService
Here are the versions of the different packages :
Thank you in advance for your answers.
Upvotes: 2
Views: 1259
Reputation: 79744
Add "allowSyntheticDefaultImports": true
in the compilerOptions
section of your tsconfig.json
and use
import PouchDB from 'pouchdb';
Upvotes: 7
Reputation: 1043
I had the same problem. But I solved it by adding the PouchDb cdn to my index.html page
<script src="//cdn.jsdelivr.net/pouchdb/6.4.3/pouchdb.min.js"></script>
And then after I used it in my code like this
declare const PouchDB;
const _DB_ = new PouchDB('dbname');
Upvotes: 1