canirequire › CommonJS › 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.
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.
| Runtime | require("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).
| Versions | Format | First published |
|---|---|---|
| 0.1.0 – 1.0.38 | CommonJS | Jul 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
- 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
- querystring 0.2.1CommonJS
- postcss-loader 8.2.1CommonJS
- resize-observer-polyfill 1.5.1CommonJS
- socket.io-client 4.8.3Dual
- request 2.88.2CommonJS
- postcss-calc 11.1.1ESM-only
- nodemon 3.1.14CommonJS
- ramda 0.32.0Dual