代码之家  ›  专栏  ›  技术社区  ›  Daniel Khoroshko

类型错误:pouchdb_1。默认值不是构造函数

  •  1
  • Daniel Khoroshko  · 技术社区  · 9 年前

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

    邮袋DB 6.3.4+@类型/邮袋DB

    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');
    
    3 回复  |  直到 9 年前
        1
  •  2
  •   Mustansir Zia    9 年前

    来自PouchDB npm .

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

    .default 在这种情况下。

        2
  •  0
  •   MoleIsKing    8 年前

    我补充道 @types/pouchdb": "^6.3.2"

        3
  •  0
  •   Alexandre Bonhomme    6 年前

    我的解决方案是安装键入:

    npm i -D @types/pouchdb
    

    并导入如下内容:

    import * as PouchDB from 'pouchdb';
    

    this.db = new PouchDB('my_db');
    
    推荐文章