typicode / lowdb

Simple and fast JSON database
MIT License
21.49k stars 923 forks source link

Instance of db is undefined when exported to other Modules , its working on the one that exported it ! #539

Closed mubaidr closed 2 years ago

mubaidr commented 2 years ago

Source module:

// https://www.npmjs.com/package/lowdb/v/1.0.0

import low from 'lowdb';
import FileSync from 'lowdb/adapters/FileSync';

const adapter = new FileSync('./database/db.json');
const db = low(adapter);

// Set some defaults
db.defaults({
    bots: [],
    deviceDescriptors: [],
    userAgents: [],
    screenSizes: [],
}).write();

export default db;

Target module:

import db from '../database/db';

console.log(db.getState());

db is defined, db.getState is defined (as per VSC). But at runtime causes following error:

TypeError: db_1.default.getState is not a function

Nodejs: 18.1 LowDb: 1.0.0

typicode commented 2 years ago

Sorry, I don't know why you're getting this issue. I would suggest trying to upgrade lowdb if possible.