canirequire

canirequireESM-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.

Latest
14.2.6 (Mar 3, 2026)
Module format
ESM-only
Last CommonJS version
13.0.4
ESM-only since
14.0.0 (Jul 12, 2022)
TypeScript types
None
Node engines
>= 14
Weekly downloads
2.9M
License
MIT

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.

Runtimerequire("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.4

Module format by version

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

VersionsFormatFirst published
14.0.0 – 14.2.6ESM-onlyJul 12, 2022
7.0.0 – 13.0.4CommonJSMay 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

Similar popularity