typicode / lowdb

Simple and fast JSON database
MIT License
21.35k stars 918 forks source link

how do I use this without esm #512

Closed NickKelly1 closed 2 years ago

NickKelly1 commented 2 years ago

Hi,

How do I install this package without ESM? Is there a non-ESM version?

typicode commented 2 years ago

Hi,

I'd recommend using v1 which is stable and used in JSON Server. When ready you can switch to v2.

gsouf commented 2 years ago

@typicode isn't v3 stable now? I'm not sure if this is related to this issue but I got ESM error when I use it with babel-node in this way:

import { Low, JSONFile } from 'lowdb';

Error is:

Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/lowdb/lib/index.js from index.js not supported.
Instead change the require of node_modules/lowdb/lib/index.js in index.js to a dynamic import() which is available in all CommonJS modules.

Note that tt's working well when bundled with webpack.

I'm not really familiar with all these import/require specifications. If you have any idea that can help me finding a solution. Otherwise I'm happy doing a bit of research to figure out

luukdv commented 2 years ago

@gsouf This might be helpful to you: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

gsouf commented 2 years ago

@luukdv thanks, but there are just way too many incompatibilities when we use this for an app that we bundle for the web, and this is a real pain to fix. I ended bundling the sources using esbuild with --platform=node.