canirequire

canirequireCommonJS › npm

Is npm ESM-only? Can you require() it?

a package manager for JavaScript

Last verified Sep 9, 2026 against npm@12.0.2. JSON

CommonJS CommonJS — require() works on every Node.js version

npm ships CommonJS only. require("npm") works everywhere. import "npm" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

Latest
12.0.2 (Jul 29, 2026)
Module format
CommonJS
Last CommonJS version
12.0.2
TypeScript types
@types/npm
Node engines
^22.22.2 || ^24.15.0 || >=26.0.0
Weekly downloads
13.9M
License
Artistic-2.0

Does npm@12.0.2 actually load? Runtime test results

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

Runtimerequire("npm")import "npm"
Node.js 18✗ failsError: The programmatic API was removed in npm v8.0.0✗ failsError: The programmatic API was removed in npm v8.0.0
Node.js 20✗ failsError: The programmatic API was removed in npm v8.0.0✗ failsError: The programmatic API was removed in npm v8.0.0
Node.js 22✗ failsError: The programmatic API was removed in npm v8.0.0✗ failsError: The programmatic API was removed in npm v8.0.0
Node.js 24✗ failsError: The programmatic API was removed in npm v8.0.0✗ failsError: The programmatic API was removed in npm v8.0.0
Node.js 26✗ failsError: The programmatic API was removed in npm v8.0.0✗ failsError: The programmatic API was removed in npm v8.0.0
Bun 1.4✗ failserror: The programmatic API was removed in npm v8.0.0✗ failserror: The programmatic API was removed in npm v8.0.0

A failing require() on a CommonJS package usually means the package needs a browser/DOM global, a peer dependency, or a native binary that is not available in a bare Node.js process.

How to import npm

ES modules (import)

import npm from "npm";

Named imports from a CommonJS package only work when Node.js can statically detect them. If a named import fails, use the default import and destructure.

CommonJS (require)

const npm = require("npm");

Module format by version

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

VersionsFormatFirst published
10.2.3 – 12.0.2CommonJSNov 2, 2023

Frequently asked

Is npm ESM-only?

npm@12.0.2 is a CommonJS package. npm ships CommonJS only. require("npm") works everywhere. import "npm" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

Can I import npm with ES module syntax?

Yes. import npm from "npm" works in Node.js and Bun because they support importing CommonJS modules. Named imports work only when Node.js can statically detect the exports.

Does npm work in Bun?

Importing npm failed in Bun 1.4 on Sep 9, 2026: error: The programmatic API was removed in npm v8.0.0

Does npm ship TypeScript types?

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

Links

Other commonjs packages

Similar popularity