canirequire

canirequireDual (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. JSON

Dual (CommonJS + ESM) Dual package — both require() and import work

js-cookie publishes both a CommonJS entry and a native ESM entry (ESM added in 3.0.0). require("js-cookie") and import "js-cookie" both work on every supported Node.js version and in Bun.

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

How to import js-cookie

ES modules (import)

import jsCookie from "js-cookie";

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 (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") and import "js-cookie" both work on every supported Node.js version and in Bun.

Can I require js-cookie?

Yes. js-cookie ships a CommonJS entry, so require("js-cookie") works on every Node.js version, alongside the native ESM entry for import.

Does js-cookie work in Bun?

Yes. import "js-cookie" loaded successfully in Bun 1.4 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