Skip to content

Upgrading js-cookie 2 to 3

Breaking2.2.1 → 3.0.8Breaking10Security1Platform2New3Changed6Fixed12Other5

BreakingUpgrade verdict

9 breaking changes and 2 platform requirement changes and a security fix.

  • You can no longer change global default cookie settings. Instead, create a separate cookie API with your own defaults.
  • You must now convert objects to and from JSON yourself when storing them in cookies.
  • You must now pass an object naming which converters you want, such as a read converter, instead of a bare function.
  • The package can no longer be installed through Bower.
Top 5 of 12 that need code or config changes
Breaking9
Removes defaults in favor of Cookies.withAttributes() for creating an API instance with predefined cookie attributes.
defaultsCookies.withAttributes()api.set()
Removes built-in JSON support, including getJSON() and automatic stringifying in set().
getJSON()set()Cookies.set()Cookies.get()JSON.stringify()JSON.parse()
withConverter() no longer accepts a function argument and requires an object with explicit converter types.
withConverter()
Removes support for Bower.
Exposes configured attributes as an immutable attributes property that cannot be changed to configure the API.
attributesdefaults
Removes the falsy-return fallback to the internal converter in custom read converters; default converters are now exposed as Cookies.converter.
Cookies.converterCookies.converter.read()
Exposes configured converters as an immutable converter property that cannot be changed to configure the API.
converter
Cookie name and value encoding now percent-encodes only ";" and "=" in names and ";" in values, instead of the stricter RFC 6265 section 4 rules.
Makes the entire api instance immutable.
Security1
Prevents cookie attribute injection (CVE-2026-46625).
High · CVSS 7.5
Platform2
No longer supports Node below 12 when building, targeting LTS versions only.
No longer supports Node 6 when building; only LTS versions are supported.