canirequire › CommonJS › 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.
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.
| Runtime | require("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).
| Versions | Format | First published |
|---|---|---|
| 10.2.3 – 12.0.2 | CommonJS | Nov 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
- debug 4.4.3CommonJS
- semver 7.8.5CommonJS
- ms 2.1.3CommonJS
- picomatch 4.0.7CommonJS
- ajv 8.20.0CommonJS
- source-map 0.8.0CommonJS
- react-is 19.2.8CommonJS
- readable-stream 4.7.0CommonJS
Similar popularity
- react-i18next 17.0.13Dual
- raf 3.4.1CommonJS
- npmlog 7.0.1CommonJS
- three 0.186.0Dual
- vue 3.5.42Dual
- graphql-tag 2.12.7CommonJS
- mocha 12.0.0ESM-only
- html-webpack-plugin 5.6.8CommonJS