简体   繁体   中英

How can I import NeDB as ES Mobule

I need to import NeDB and I need to do this using ES Module , what I need from NeDB is DataStore .

When I try to import DataStore using the usual synthax:

import { DataStore } from 'nedb';

I have this error:

Named export 'Datastore' not found. The requested module 'nedb' is a CommonJS module,
which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export

I tried:

import * as nedb from 'nedb';
console.log(nedb)
// Output
// [Function: Datastore]

I also tried:

import nedb from 'nedb';
const { DataStore } = nedb;
console.log(DataStore);
// Output
// undefined

But how can I access Datastore ?

Thx,
Maxime

I finnaly foud the solution:

import DataStore from 'nedb';
// Then I can use :
new DataStore(...); // works

I don't know how I missed it... Thx everyone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM