canirequire › Dual (CommonJS + ESM) › socket.io
Is socket.io ESM-only? Can you require() it?
node.js realtime framework server
Last verified Sep 9, 2026 against socket.io@4.8.3. JSON
Dual (CommonJS + ESM) Dual package — both require() and import work
socket.io publishes both a CommonJS entry and a native ESM entry (ESM added in 3.0.0). require("socket.io") and import "socket.io" both work on every supported Node.js version and in Bun.
Does socket.io@4.8.3 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("socket.io") from a CommonJS file and import "socket.io" from an ES module.
| Runtime | require("socket.io") | import "socket.io" |
|---|---|---|
| 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 socket.io
ES modules (import)
import socketIo from "socket.io";CommonJS (require)
const socketIo = require("socket.io");Module format by version
Derived from the type, main and exports fields of every stable release on npm (150 versions; the newest 60 shown).
| Versions | Format | First published |
|---|---|---|
| 3.0.0 – 4.8.3 | Dual (CommonJS + ESM) | Nov 5, 2020 |
| 1.5.1 – 2.5.1 | CommonJS | Oct 24, 2016 |
Frequently asked
Is socket.io ESM-only?
socket.io@4.8.3 ships CommonJS and ESM builds. socket.io publishes both a CommonJS entry and a native ESM entry (ESM added in 3.0.0). require("socket.io") and import "socket.io" both work on every supported Node.js version and in Bun.
Can I require socket.io?
Yes. socket.io ships a CommonJS entry, so require("socket.io") works on every Node.js version, alongside the native ESM entry for import.
Does socket.io work in Bun?
Yes. import "socket.io" loaded successfully in Bun 1.4 on Sep 9, 2026.
Does socket.io ship TypeScript types?
Yes. socket.io bundles its own type declarations; no @types package is needed.
Links
Other dual (commonjs + esm) packages
- minimatch 10.2.6Dual
- brace-expansion 5.0.9Dual
- lru-cache 11.5.2Dual
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
- js-yaml 5.4.1Dual
Similar popularity
- es6-promise 4.2.8CommonJS
- cssnano 9.0.4ESM-only
- jwt-decode 4.0.0Dual
- lodash.get 4.4.2CommonJS
- assert 2.1.0CommonJS
- moment-timezone 0.6.3CommonJS
- superagent 10.3.0CommonJS
- supertest 7.2.2CommonJS