TypeError: pouchdb_1.default is not a constructor

TypeError: pouchdb_1.default is not a constructor

我之前在基于浏览器的项目上使用过 PouchDB,一切正常,但是在一个新的节点项目上,无论我如何导入模块,我都会遇到这个错误

Pouchdb 6.3.4 + @types/pouchdb

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

结果代码:

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

我尝试了所有可能的导入方式(import =, const =, import * as, import { })

答案(感谢 Mustansir Zia)

const PouchDB = require('pouchdb');

来自 PouchDB 的 npm

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

让我们看看使用 require 是否可行。在这种情况下,Babel 不必附加 .default

我将 @types/pouchdb": "^6.3.2" 添加到 devDependencies 部分的 package.json。

我的解决方案是安装 typing :

npm i -D @types/pouchdb

并导入如下:

import * as PouchDB from 'pouchdb';

之后一切都按预期进行:

this.db = new PouchDB('my_db');