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

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

Logic-less {{mustache}} templates with JavaScript

Last verified Sep 9, 2026 against mustache@4.2.0.

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

## What to do

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

## Facts

- Latest: 4.2.0 (Mar 28, 2021)
- Module format: Dual (CommonJS + ESM)
- Last CommonJS version: 4.2.0
- Native ESM since: 4.2.0
- TypeScript types: @types/mustache
- Node engines: not declared
- Weekly downloads: 15.6M
- License: MIT

## Runtime test results for mustache@4.2.0

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

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

ES modules:

```js
import * as mustache from "mustache";
```

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

CommonJS:

```js
const mustache = require("mustache");
```

## Module format by version

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

| Versions | Format | First published |
|---|---|---|
| 4.2.0 | Dual (CommonJS + ESM) | Mar 28, 2021 |
| 0.4.0 – 4.1.0 | CommonJS | Jan 9, 2012 |

## Frequently asked

**Is mustache ESM-only?**

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

**Can I require mustache?**

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

**Does mustache work in Bun?**

Yes. import "mustache" loaded successfully in Bun 1.4.0 on Sep 9, 2026.

**Does mustache ship TypeScript types?**

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

## Links

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