我需要导入NeDB,我需要使用ES Module来实现这一点,我需要从NeDB中获取DataStore。
当我尝试使用通常的synthax导入DataStore时:
import { DataStore } from 'nedb';我有一个错误:
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我试过:
import * as nedb from 'nedb';
console.log(nedb)
// Output
// [Function: Datastore]我也试过:
import nedb from 'nedb';
const { DataStore } = nedb;
console.log(DataStore);
// Output
// undefined但是我如何访问Datastore呢?
Thx,
马克西姆
发布于 2022-07-29 11:15:39
我终于找到了解决办法:
import DataStore from 'nedb';
// Then I can use :
new DataStore(...); // works我不知道我怎么会错过..。Thx所有人
https://stackoverflow.com/questions/73164570
复制相似问题