typicode / lowdb

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

Fixed issue with importing #503

Closed mxgordon closed 2 years ago

mxgordon commented 2 years ago

I had just installed this package, but I was unable to import it.

import { LowSync } from 'lowdb'

It kept failing with

Cannot find module: 'lowdb'. Make sure this package is installed.

You can install this package by running: npm install lowdb.

I tried reinstalling it, deleting node_modules and then installing, nothing worked. Eventually, I saw that you can add "main": "./lib/index.js", to the package.json in the lowdb folder. I did that and it worked. So I'm just making this PR to hopefully fix it.

mxgordon commented 2 years ago

btw I had to do the same thing to steno too

typicode commented 2 years ago

Hi @JohnnyWobble,

Thanks for the PR. Which tool are you using? It should work with recent version of Node and ESM enabled in package.json using "type": "module"

You may want to check: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

mxgordon commented 2 years ago

I was using this as part of a react app, so I don't think ESM compatibility was a problem, I wasn't running the newest Node version, but it wasn't too old. Disregard this PR if its not necessary, its just something I found helpful

typicode commented 2 years ago

Closing as for now there's no plan to have dual esm + cjs support. I do hope/think that projects will catch up with esm. Thanks for the PR :)