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. Markdown · JSON
CommonJS CommonJS on paper — require() failed in our runtime test
npm declares a CommonJS entry only, but require("npm") failed on every Node.js version in our probe: The programmatic API was removed in npm v8.0.0. import "npm" resolves to the same file, so it fails the same way. That usually means a missing peer dependency, a browser-only global, or a package that is not meant to be loaded directly; see the runtime table below.
What to do
- require("npm") failed in our probe on every Node.js version (The programmatic API was removed in npm v8.0.0); check the package README for peer dependencies or setup before relying on it.
- From ES modules use the default import: import npm from "npm"; then destructure. Named imports only work when Node.js can statically detect the exports.
- TypeScript: npm install -D @types/npm
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 | ✗ failsError |
| Node.js 20 | ✗ failsError | ✗ failsError |
| Node.js 22 | ✗ failsError | ✗ failsError |
| Node.js 24 | ✗ failsError | ✗ failsError |
| Node.js 26 | ✗ failsError | ✗ failsError |
| Bun 1.4.0 | ✗ failsError | ✗ failsError |
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)
// require("npm") failed in our probe on every Node.js version we test (The programmatic API was removed in npm v8.0.0); see the runtime table.
const npm = require("npm");Module 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 (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 declares a CommonJS entry, but require() fails at runtime. npm declares a CommonJS entry only, but require("npm") failed on every Node.js version in our probe: The programmatic API was removed in npm v8.0.0. import "npm" resolves to the same file, so it fails the same way. That usually means a missing peer dependency, a browser-only global, or a package that is not meant to be loaded directly; see the runtime table below.
Can I require npm?
Not in practice. npm declares a CommonJS entry, but require("npm") failed on every Node.js version in our probe: The programmatic API was removed in npm v8.0.0. Check the package README for peer dependencies or setup before relying on it.
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.0 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.0ESM-only
- vue 3.5.42Dual
- @rollup/plugin-node-resolve 16.0.3Dual
- graphql-tag 2.12.7CommonJS
- mocha 12.0.0ESM-only