How can I import NeDB as ES Mobule

226 Views Asked by At

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

1

There are 1 best solutions below

0
nem0z On BEST ANSWER

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