lowdb: node@14.16.0 Error [ERR_REQUIRE_ESM]
node: 14.16.0 electron: 13.0.1 webpack: 4.46.0
import { Low, JSONFile } from 'lowdb'
const adapter = new JSONFile('example.json')
export const lowdb = new Low(adapter)
The above code run error, ERR_REQUIRE_ESM
has been prompted, what is the solution?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 12
- Comments: 19 (1 by maintainers)
I opened a PR opened here to address this issue.
You can test it by installing the package from PR’s
lib
branchnpm
yarn
Closing as I prefer to keep v2 a pure ESM package. I’m aware not every project can migrate to ESM right now, but tools and libraries are catching up. If possible, I’d recommend migrating your project to ESM.
For anyone looking to fix the error, please follow this excellent guide: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
https://pencilflip.medium.com/using-es-modules-with-commonjs-modules-in-node-js-1015786dab03
Here some solutions:
"module": "commonjs"
intsconfig.json
, run build and put project into yournode_modules
, you can remove src dict manually.packages
if you are using lerna to manage your project.I’m having the same issue here…
Convenient timing, I’m also seeing this issue.
I have the same problem.