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.66k stars 794 forks source link

strange error #469

Closed andrewvlgafc closed 8 months ago

andrewvlgafc commented 8 months ago

Hello.

install nanoid v4.0.2 because nodejs is 14.17.6

import as

import { nanoid } from 'nanoid'

on start see error

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: \node_modules\nanoid\index.js require() of ES modules is not supported. require() of \node_modules\nanoid\index.js from \dist\app\PhotoService\upload\init.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from \node_modules\nanoid\package.json.

is possible to start nanoid on nodejs 14.17.6?

ai commented 8 months ago

Use nanoid@3 for legacy project.

The newest Nano ID is for ESM projects.

I am closing this issue as duplicate.

andrewvlgafc commented 8 months ago

thanks for fast answer