canirequire › ESM-only › serve
Is serve ESM-only? Can you require() it?
Static file serving and directory listing
Last verified Sep 9, 2026 against serve@14.2.6. JSON
ESM-only ESM-only since 14.0.0 — last CommonJS version is 13.0.4
serve dropped its CommonJS build in 14.0.0 (July 2022). The last version you can require() on every Node.js version, including 18 and older, is 13.0.4, published Jul 6, 2022.
require("serve") failed in our probe on Node.js 20+ as well. See the runtime matrix below for the exact error.
Does serve@14.2.6 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("serve") from a CommonJS file and import "serve" from an ES module.
| Runtime | require("serve") | import "serve" |
|---|---|---|
| Node.js 18 | ✗ failsMODULE_NOT_FOUND | ✗ failsERR_MODULE_NOT_FOUND |
| Node.js 20 | ✗ failsMODULE_NOT_FOUND | ✗ failsERR_MODULE_NOT_FOUND |
| Node.js 22 | ✗ failsMODULE_NOT_FOUND | ✗ failsERR_MODULE_NOT_FOUND |
| Node.js 24 | ✗ failsMODULE_NOT_FOUND | ✗ failsERR_MODULE_NOT_FOUND |
| Node.js 26 | ✗ failsMODULE_NOT_FOUND | ✗ failsERR_MODULE_NOT_FOUND |
| Bun 1.4 | ✗ failserror: Cannot find package 'serve' from '/Users/boat/Projects/top-seo/data/probe-work/serve/req.cjs' | ✗ failserror: Cannot find package 'serve' from '/Users/boat/Projects/top-seo/data/probe-work/serve/imp.mjs' |
How to import serve
ES modules (import)
import serve from "serve";CommonJS (require)
// Node.js 20.19+ / 22.12+ / newer (package has no top-level await):
const serve = require("serve");
// Any Node.js version:
const serve = await import("serve");
// Or pin the last CommonJS release:
// npm install serve@13.0.4Module format by version
Derived from the type, main and exports fields of every stable release on npm (154 versions; the newest 60 shown).
| Versions | Format | First published |
|---|---|---|
| 14.0.0 – 14.2.6 | ESM-only | Jul 12, 2022 |
| 7.0.0 – 13.0.4 | CommonJS | May 28, 2018 |
Frequently asked
Is serve ESM-only?
serve@14.2.6 is ESM-only. serve dropped its CommonJS build in 14.0.0 (July 2022). The last version you can require() on every Node.js version, including 18 and older, is 13.0.4, published Jul 6, 2022.
Which version of serve still supports CommonJS / require()?
13.0.4 is the last version of serve with a CommonJS build. Install it with "npm install serve@13.0.4". Every version from 14.0.0 on is ESM-only.
How do I use serve from a CommonJS file?
Use a dynamic import: const mod = await import("serve"). On Node.js 20.19+, 22.12+ and newer, a plain require("serve") also works for ESM packages that do not use top-level await. Alternatively pin serve@13.0.4.
Does serve work in Bun?
Importing serve failed in Bun 1.4 on Sep 9, 2026: error: Cannot find package 'serve' from '/Users/boat/Projects/top-seo/data/probe-work/serve/imp.mjs'
Does serve ship TypeScript types?
No. serve ships no type declarations and there is no @types package for it.
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 - tslib 2.8.1last CJS
2.5.2 - string-width 8.2.2last CJS
4.2.3 - ansi-regex 6.3.0last CJS
5.0.1
Similar popularity
- tsconfig 7.0.0CommonJS
- babel-plugin-module-resolver 5.0.3CommonJS
- react-helmet 6.1.0CommonJS
- karma 6.4.4CommonJS
- eslint-plugin-eslint-comments 3.2.0CommonJS
- react-intl 10.1.26ESM-only
- bunyan 1.8.15CommonJS
- karma-chrome-launcher 3.2.0CommonJS