Daniel Khoroshko Daniel Khoroshko - 1 month ago 26
TypeScript Question

TypeError: pouchdb_1.default is not a constructor

I've used PouchDB on browser based projects before and everything was alright, but on a new node project I get this error no matter how I import the module

Pouchdb 6.3.4 + @types/pouchdb

import PouchDB from 'pouchdb';
this.userDB = new PouchDB('db');
//TypeError: pouchdb_1.default is not a constructor


Resulting code:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const pouchdb_1 = require("pouchdb");
this.userDB = new pouchdb_1.default('db')


I've tried to import in all possible ways (import =, const =, import * as, import { })

THE ANSWER (thanks to Mustansir Zia)

const PouchDB = require('pouchdb');

Answer Source

From PouchDB's npm.

var PouchDB = require('pouchdb');
var db = new PouchDB('my_db');

Let's see if it works out using require. Babel doesn't have to append the .default to it in that case.