canirequire

canirequireCommonJS › portfinder

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

A simple tool to find an open port on the current machine

Last verified Sep 9, 2026 against portfinder@1.0.38. JSON

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

portfinder ships CommonJS only. require("portfinder") works everywhere. import "portfinder" 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
1.0.38 (Sep 12, 2025)
Module format
CommonJS
Last CommonJS version
1.0.38
TypeScript types
Bundled
Node engines
>= 10.12
Weekly downloads
12.6M
License
MIT

Does portfinder@1.0.38 actually load? Runtime test results

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

Runtimerequire("portfinder")import "portfinder"
Node.js 18✓ works✓ works
Node.js 20✓ works✓ works
Node.js 22✓ works✓ works
Node.js 24✓ works✓ works
Node.js 26✓ works✓ works
Bun 1.4✓ works✓ works

How to import portfinder

ES modules (import)

import portfinder from "portfinder";

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 portfinder = require("portfinder");

Module format by version

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

VersionsFormatFirst published
0.1.0 – 1.0.38CommonJSJul 8, 2011

Frequently asked

Is portfinder ESM-only?

portfinder@1.0.38 is a CommonJS package. portfinder ships CommonJS only. require("portfinder") works everywhere. import "portfinder" 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 portfinder with ES module syntax?

Yes. import portfinder from "portfinder" 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 portfinder work in Bun?

Yes. import "portfinder" loaded successfully in Bun 1.4 on Sep 9, 2026.

Does portfinder ship TypeScript types?

Yes. portfinder bundles its own type declarations; no @types package is needed.

Links

Other commonjs packages

Similar popularity