Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't import PouchDB into Angular 5.2.0 application

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 :

  • PouchDB : 6.4.3
  • @types/pouchdb : 6.3.2
  • Angular packages : 5.2.0
  • @angular/cli : 1.7.4

Thank you in advance for your answers.

like image 458
Kevk Avatar asked Dec 14 '25 01:12

Kevk


1 Answers

Add "allowSyntheticDefaultImports": true in the compilerOptions section of your tsconfig.json

and use

import PouchDB from 'pouchdb';
like image 128
Flimzy Avatar answered Dec 16 '25 22:12

Flimzy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!