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

> npm@12.0.2 declares a CommonJS entry, but require() fails at runtime. CommonJS on paper — require() failed in our runtime test.

a package manager for JavaScript

Last verified Sep 9, 2026 against npm@12.0.2.

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

1. 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.
2. 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.
3. TypeScript: npm install -D @types/npm

## Facts

- 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

## Runtime test results for npm@12.0.2

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 | fails (Error) | fails (Error) |
| Node.js 20 | fails (Error) | fails (Error) |
| Node.js 22 | fails (Error) | fails (Error) |
| Node.js 24 | fails (Error) | fails (Error) |
| Node.js 26 | fails (Error) | fails (Error) |
| Bun 1.4.0 | fails (Error) | fails (Error) |

## How to import npm

ES modules:

```js
import npm from "npm";
```

CommonJS:

```js
// 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 (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

- [npm on npm](https://www.npmjs.com/package/npm)
- [Source repository](https://github.com/npm/cli)
- [HTML version](https://canirequire.com/package/npm/)
- [JSON version](https://canirequire.com/package/npm.json)

---

For scripts and AI agents: any package is at https://canirequire.com/package/<name>/index.md (Markdown) or https://canirequire.com/package/<name>.json (JSON); the site index is https://canirequire.com/llms.txt. Fetch the URL directly; no search needed.
