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

> js-cookie@3.0.8 ships CommonJS and ESM builds. Dual package — require() works on every Node.js version we test; import works too.

A simple, lightweight JavaScript API for handling cookies

Last verified Sep 9, 2026 against js-cookie@3.0.8.

js-cookie publishes both a CommonJS entry and a native ESM entry (ESM added in 3.0.0). require("js-cookie") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "js-cookie" works alongside it.

## What to do

1. Nothing to change. require("js-cookie") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import * as jsCookie from "js-cookie" works alongside it; use named imports for what the ESM entry exports.
2. TypeScript: npm install -D @types/js-cookie

## Facts

- Latest: 3.0.8 (May 29, 2026)
- Module format: Dual (CommonJS + ESM)
- Last CommonJS version: 3.0.8
- Native ESM since: 3.0.0
- TypeScript types: @types/js-cookie
- Node engines: not declared
- Weekly downloads: 26.6M
- License: MIT

## Runtime test results for js-cookie@3.0.8

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

| Runtime | require("js-cookie") | import "js-cookie" |
|---|---|---|
| Node.js 18 | works | 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 js-cookie

ES modules:

```js
import * as jsCookie from "js-cookie";
```

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

CommonJS:

```js
const jsCookie = require("js-cookie");
```

## Module format by version

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

| Versions | Format | First published |
|---|---|---|
| 3.0.0 – 3.0.8 | Dual (CommonJS + ESM) | Jul 26, 2021 |
| 1.5.0 – 2.2.1 | CommonJS | Apr 15, 2015 |

## Frequently asked

**Is js-cookie ESM-only?**

js-cookie@3.0.8 ships CommonJS and ESM builds. js-cookie publishes both a CommonJS entry and a native ESM entry (ESM added in 3.0.0). require("js-cookie") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "js-cookie" works alongside it.

**Can I require js-cookie?**

Yes. js-cookie ships a CommonJS entry alongside the native ESM entry. require("js-cookie") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun.

**Does js-cookie work in Bun?**

Yes. import "js-cookie" loaded successfully in Bun 1.4.0 on Sep 9, 2026.

**Does js-cookie ship TypeScript types?**

Not bundled. Install the community types with "npm install -D @types/js-cookie".

## Links

- [js-cookie on npm](https://www.npmjs.com/package/js-cookie)
- [Source repository](https://github.com/js-cookie/js-cookie)
- [HTML version](https://canirequire.com/package/js-cookie/)
- [JSON version](https://canirequire.com/package/js-cookie.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.
