canirequire › ESM-only › color-string
Is color-string ESM-only? Can you require() it?
Parser and generator for CSS color strings
Last verified Sep 9, 2026 against color-string@2.1.4. Markdown · JSON
ESM-only ESM-only since 2.0.0 — last CommonJS version is 1.9.1
color-string dropped its CommonJS build in 2.0.0 (February 2025). The last version with a plain require()-able CommonJS entry is 1.9.1, published Apr 22, 2022.
On Node.js 20.19+, 22.12+ and newer, require("color-string") works with the latest version: Node.js loads synchronous ES modules through require(). Verified on Node.js 20, 22, 24 and 26. On Node.js 18, which has no require(esm), require("color-string") fails with ERR_REQUIRE_ESM.
What to do
- On Node.js 20.19+, 22.12+ and newer, require("color-string") works with the latest version: Node.js loads synchronous ES modules through require(). Verified on Node.js 20, 22, 24 and 26.
- From a CommonJS file, use a dynamic import inside an async function: const colorString = await import("color-string"). That works on every Node.js version the package supports (>=18).
- If you need a synchronous require() or run Node.js 18: npm install color-string@1.9.1, the last CommonJS release (published Apr 22, 2022).
- TypeScript: types are bundled; install nothing extra.
Does color-string@2.1.4 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("color-string") from a CommonJS file and import "color-string" from an ES module.
| Runtime | require("color-string") | import "color-string" |
|---|---|---|
| Node.js 18 | ✗ failsERR_REQUIRE_ESM | ✓ 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 color-string
ES modules (import)
import * as colorString from "color-string";Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.
CommonJS (require)
// Node.js 20.19+, 22.12+ and newer (verified):
const colorString = require("color-string");
// Any Node.js version the package supports (>=18), from an async function:
async function main() {
const colorString = await import("color-string");
}
// Or pin the last CommonJS release:
// npm install color-string@1.9.1Module format by version
Derived from the type, main and exports fields of every stable release on npm, corrected where a runtime test of that version contradicted them (42 versions; the newest 42 shown).
| Versions | Format | First published |
|---|---|---|
| 2.0.0 – 2.1.4 | ESM-only | Feb 6, 2025 |
| 0.1.0 – 1.9.1 | CommonJS | Jun 19, 2011 |
Frequently asked
Is color-string ESM-only?
color-string@2.1.4 is ESM-only. color-string dropped its CommonJS build in 2.0.0 (February 2025). The last version with a plain require()-able CommonJS entry is 1.9.1, published Apr 22, 2022.
Which version of color-string still supports CommonJS / require()?
1.9.1 is the last version of color-string with a CommonJS build. Install it with "npm install color-string@1.9.1". Every version from 2.0.0 on is ESM-only.
How do I use color-string from a CommonJS file?
From a CommonJS file, use a dynamic import inside an async function: const colorString = await import("color-string"). That works on every Node.js version the package supports (>=18). On Node.js 20.19+, 22.12+ and newer, require("color-string") works with the latest version: Node.js loads synchronous ES modules through require(). Verified on Node.js 20, 22, 24 and 26. Alternatively pin color-string@1.9.1.
Does color-string work in Bun?
Yes. import "color-string" loaded successfully in Bun 1.4.0 on Sep 9, 2026.
Does color-string ship TypeScript types?
Yes. color-string bundles its own type declarations; no @types package is needed.
Links
Other esm-only packages
- ansi-styles 7.0.0last CJS
5.2.0 - strip-ansi 7.2.0last CJS
6.0.1 - commander 15.0.0last CJS
14.0.3 - supports-color 11.0.0last CJS
8.1.1 - chalk 6.0.0last CJS
4.1.2 - string-width 8.2.2last CJS
4.2.3 - ansi-regex 6.3.0last CJS
5.0.1 - escape-string-regexp 5.0.0last CJS
4.0.0
Similar popularity
- @smithy/protocol-http 5.6.2CommonJS
- dotenv-expand 1000.0.0CommonJS
- psl 1.15.0Dual
- meow 14.1.0ESM-only
- is-descriptor 3.1.2CommonJS
- dom-helpers 6.0.1Dual
- @smithy/middleware-endpoint 4.7.2CommonJS
- ejs 6.0.1Dual