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

> whatwg-encoding@3.1.1 is a CommonJS package. CommonJS — require() works on every Node.js version we test.

Decode strings according to the WHATWG Encoding Standard

Last verified Sep 9, 2026 against whatwg-encoding@3.1.1.

whatwg-encoding ships CommonJS only. require("whatwg-encoding") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >=18. import "whatwg-encoding" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

**Deprecated:** Use @exodus/bytes instead for a more spec-conformant and faster implementation

## What to do

1. require("whatwg-encoding") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >=18.
2. From ES modules use the default import: import whatwgEncoding from "whatwg-encoding"; then destructure. Named imports only work when Node.js can statically detect the exports.
3. TypeScript: npm install -D @types/whatwg-encoding
4. This package is deprecated: Use @exodus/bytes instead for a more spec-conformant and faster implementation

## Facts

- Latest: 3.1.1 (Nov 12, 2023)
- Module format: CommonJS
- Last CommonJS version: 3.1.1
- TypeScript types: @types/whatwg-encoding
- Node engines: >=18
- Weekly downloads: 48.9M
- License: MIT

## Runtime test results for whatwg-encoding@3.1.1

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

| Runtime | require("whatwg-encoding") | import "whatwg-encoding" |
|---|---|---|
| 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 whatwg-encoding

ES modules:

```js
import whatwgEncoding from "whatwg-encoding";
```

CommonJS:

```js
const whatwgEncoding = require("whatwg-encoding");
```

## Module format by version

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

| Versions | Format | First published |
|---|---|---|
| 1.0.0 – 3.1.1 | CommonJS | Oct 16, 2016 |

## Frequently asked

**Is whatwg-encoding ESM-only?**

whatwg-encoding@3.1.1 is a CommonJS package. whatwg-encoding ships CommonJS only. require("whatwg-encoding") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >=18. import "whatwg-encoding" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

**Can I import whatwg-encoding with ES module syntax?**

Yes. import whatwgEncoding from "whatwg-encoding" works in Node.js and Bun because they support importing CommonJS modules. Named imports work only when Node.js can statically detect the exports.

**Does whatwg-encoding work in Bun?**

Yes. import "whatwg-encoding" loaded successfully in Bun 1.4.0 on Sep 9, 2026.

**Does whatwg-encoding ship TypeScript types?**

Not bundled. Install the community types with "npm install -D @types/whatwg-encoding".

## Links

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