ai / nanoid

A tiny (124 bytes), secure, URL-friendly, unique string ID generator for JavaScript
https://zelark.github.io/nano-id-cc/
MIT License
24.22k stars 790 forks source link

ERR_REQUIRE_ESM' const { nanoid } = require("nanoid"); #465

Closed LeCongNam closed 7 months ago

LeCongNam commented 7 months ago

i'm using nanoid@5.0.4 with nestjs When i'm import like used website npm once error throw. import { nanoid } from 'nanoid' I'm downgrade version : npm install nanoid@^3.0.0 library work well. Please fix it. Why you break every think? I'm love nanoid. Please fix prolem. Thank

ai commented 7 months ago

Nano ID 4/5 works only for ESM-only app.

If you use legacy CJS, use Nano ID 3.x (you find command in docs).

We did it because supporting CJS and ESM together requires 2x code, which is not “nano”.