canirequire › Dual (CommonJS + ESM) › mustache
Is mustache ESM-only? Can you require() it?
Logic-less {{mustache}} templates with JavaScript
Last verified Sep 9, 2026 against mustache@4.2.0. JSON
Dual (CommonJS + ESM) Dual package — both require() and import work
mustache publishes both a CommonJS entry and a native ESM entry (ESM added in 4.2.0). require("mustache") and import "mustache" both work on every supported Node.js version and in Bun.
Does mustache@4.2.0 actually load? Runtime test results
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 | ✓ works | ✓ works |
How to import mustache
ES modules (import)
import mustache from "mustache";CommonJS (require)
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") and import "mustache" both work on every supported Node.js version and in Bun.
Can I require mustache?
Yes. mustache ships a CommonJS entry, so require("mustache") works on every Node.js version, alongside the native ESM entry for import.
Does mustache work in Bun?
Yes. import "mustache" loaded successfully in Bun 1.4 on Sep 9, 2026.
Does mustache ship TypeScript types?
Not bundled. Install the community types with "npm install -D @types/mustache".
Links
Other dual (commonjs + esm) packages
- minimatch 10.2.6Dual
- brace-expansion 5.0.9Dual
- lru-cache 11.5.2Dual
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
- js-yaml 5.4.1Dual
Similar popularity
- assert 2.1.0CommonJS
- moment-timezone 0.6.3CommonJS
- superagent 10.3.0CommonJS
- supertest 7.2.2CommonJS
- @storybook/addon-docs 10.6.0No entry
- md5 2.3.0CommonJS
- tsconfig-paths-webpack-plugin 4.2.0CommonJS
- connect-history-api-fallback 2.0.0CommonJS