# Is nanoid ESM-only? Can you require() it?

> nanoid@6.0.1 is ESM-only. ESM-only since 4.0.0 — last CommonJS version is 3.3.18.

A tiny (118 bytes), secure URL-friendly unique string ID generator

Last verified Sep 9, 2026 against nanoid@6.0.1.

nanoid dropped its CommonJS build in 4.0.0 (June 2022). The last version with a plain require()-able CommonJS entry is 3.3.18, published Aug 7, 2026; it declares support for Node.js ^10 || ^12 || ^13.7 || ^14 || >=15.0.1.

On Node.js 22.12+ and newer (nanoid@6.0.1 declares Node.js ^22 || ^24 || >=26), require("nanoid") works with the latest version: Node.js loads synchronous ES modules through require(). Verified on Node.js 22, 24 and 26. Node.js 18 has no require(esm), and nanoid@6.0.1 declares Node.js ^22 || ^24 || >=26, so 18 is outside its supported range anyway.

nanoid@6.0.1 declares engines "^22 || ^24 || >=26", so Node.js 18, 20 are outside its supported range regardless of module format.

## What to do

1. On Node.js 22.12+ and newer (nanoid@6.0.1 declares Node.js ^22 || ^24 || >=26), require("nanoid") works with the latest version: Node.js loads synchronous ES modules through require(). Verified on Node.js 22, 24 and 26.
2. From a CommonJS file, use a dynamic import inside an async function: const nanoid = await import("nanoid"). That works on every Node.js version the package supports (^22 || ^24 || >=26).
3. If you need a synchronous require() or run Node.js 18: npm install nanoid@3.3.18, the last CommonJS release (published Aug 7, 2026); it declares Node.js ^10 || ^12 || ^13.7 || ^14 || >=15.0.1.
4. nanoid@6.0.1 declares engines "^22 || ^24 || >=26", so Node.js 18, 20 are unsupported regardless: upgrade Node.js or pin an older release.
5. TypeScript: types are bundled; install nothing extra.

## Facts

- Latest: 6.0.1 (Aug 3, 2026)
- Module format: ESM-only
- Last CommonJS version: 3.3.18
- ESM-only since: 4.0.0 (Jun 8, 2022)
- TypeScript types: bundled
- Node engines: ^22 || ^24 || >=26
- Weekly downloads: 214.3M
- License: MIT

## Runtime test results for nanoid@6.0.1

Installed and executed on Sep 9, 2026 with require("nanoid") from a CommonJS file and import "nanoid" from an ES module.

| Runtime | require("nanoid") | import "nanoid" |
|---|---|---|
| Node.js 18 | fails (ERR_REQUIRE_ESM) | works |
| Node.js 20 | works | works |
| Node.js 22 | works | works |
| Node.js 24 | works | works |
| Node.js 26 | works | works |
| Bun 1.4.0 | works | works |

## How to import nanoid

ES modules:

```js
import * as nanoid from "nanoid";
```

Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.

CommonJS:

```js
// Node.js 22.12+ and newer (verified):
const nanoid = require("nanoid");

// Any Node.js version the package supports (^22 || ^24 || >=26), from an async function:
async function main() {
  const nanoid = await import("nanoid");
}

// Or pin the last CommonJS release (declares Node.js ^10 || ^12 || ^13.7 || ^14 || >=15.0.1):
// npm install nanoid@3.3.18
```

## Module format by version

Derived from the type, main and exports fields of every stable release on npm (132 versions; the newest 60 shown).

| Versions | Format | First published |
|---|---|---|
| 4.0.0 – 6.0.1 | ESM-only | Jun 8, 2022 |
| 3.3.6 – 3.3.18 | Dual (CommonJS + ESM) | Mar 26, 2023 |
| 3.3.5 | CommonJS | Mar 26, 2023 |
| 3.1.28 – 3.3.4 | Dual (CommonJS + ESM) | Sep 26, 2021 |
| 3.1.27 | CommonJS | Sep 26, 2021 |
| 3.1.25 – 3.1.26 | Dual (CommonJS + ESM) | Aug 12, 2021 |

## Frequently asked

**Is nanoid ESM-only?**

nanoid@6.0.1 is ESM-only. nanoid dropped its CommonJS build in 4.0.0 (June 2022). The last version with a plain require()-able CommonJS entry is 3.3.18, published Aug 7, 2026; it declares support for Node.js ^10 || ^12 || ^13.7 || ^14 || >=15.0.1.

**Which version of nanoid still supports CommonJS / require()?**

3.3.18 is the last version of nanoid with a CommonJS build; it declares Node.js ^10 || ^12 || ^13.7 || ^14 || >=15.0.1. Install it with "npm install nanoid@3.3.18". Every version from 4.0.0 on is ESM-only.

**How do I use nanoid from a CommonJS file?**

From a CommonJS file, use a dynamic import inside an async function: const nanoid = await import("nanoid"). That works on every Node.js version the package supports (^22 || ^24 || >=26). On Node.js 22.12+ and newer (nanoid@6.0.1 declares Node.js ^22 || ^24 || >=26), require("nanoid") works with the latest version: Node.js loads synchronous ES modules through require(). Verified on Node.js 22, 24 and 26. Alternatively pin nanoid@3.3.18 (declares Node.js ^10 || ^12 || ^13.7 || ^14 || >=15.0.1).

**Does nanoid work in Bun?**

Yes. import "nanoid" loaded successfully in Bun 1.4.0 on Sep 9, 2026.

**Does nanoid ship TypeScript types?**

Yes. nanoid bundles its own type declarations; no @types package is needed.

## Links

- [nanoid on npm](https://www.npmjs.com/package/nanoid)
- [Source repository](https://github.com/ai/nanoid)
- [HTML version](https://canirequire.com/package/nanoid/)
- [JSON version](https://canirequire.com/package/nanoid.json)

---

For scripts and AI agents: any package is at https://canirequire.com/package/<name>/index.md (Markdown) or https://canirequire.com/package/<name>.json (JSON); the site index is https://canirequire.com/llms.txt. Fetch the URL directly; no search needed.
