[英]How can I import NeDB as ES Mobule
我需要導入NeDB
並且我需要使用ES Module
來執行此操作,我需要NeDB
的是DataStore
。
當我嘗試使用通常的合成器導入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
?
謝謝,
馬克西姆
我最終找到了解決方案:
import DataStore from 'nedb';
// Then I can use :
new DataStore(...); // works
我不知道我是怎么錯過的……謝謝大家
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.