canirequire

canirequire › Dual (CommonJS + ESM) › js-cookie

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

A simple, lightweight JavaScript API for handling cookies

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

Dual (CommonJS + ESM) Dual package — require() works on every Node.js version we test; import works too

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
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

Does js-cookie@3.0.8 actually load? Runtime test results

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

Runtimerequire("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 (import)

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 (require)

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

Module format by version

Derived from the type, main and exports fields of every stable release on npm, corrected where a runtime test of that version contradicted them (23 versions; the newest 23 shown).

VersionsFormatFirst published
3.0.0 – 3.0.8Dual (CommonJS + ESM)Jul 26, 2021
1.5.0 – 2.2.1CommonJSApr 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

Other dual (commonjs + esm) packages

Similar popularity