canirequire › Dual (CommonJS + ESM) › discord.js
Is discord.js ESM-only? Can you require() it?
A powerful library for interacting with the Discord API
Last verified Sep 9, 2026 against discord.js@14.27.0. JSON
Dual (CommonJS + ESM) Dual package — both require() and import work
discord.js publishes both a CommonJS entry and a native ESM entry (ESM added in 12.2.0). require("discord.js") and import "discord.js" both work on every supported Node.js version and in Bun.
Does discord.js@14.27.0 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("discord.js") from a CommonJS file and import "discord.js" from an ES module.
| Runtime | require("discord.js") | import "discord.js" |
|---|---|---|
| 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 discord.js
ES modules (import)
import discordJs from "discord.js";CommonJS (require)
const discordJs = require("discord.js");Module format by version
Derived from the type, main and exports fields of every stable release on npm (217 versions; the newest 60 shown).
| Versions | Format | First published |
|---|---|---|
| 14.15.0 – 14.27.0 | Dual (CommonJS + ESM) | May 4, 2024 |
| 14.0.1 – 14.14.1 | CommonJS | Jul 17, 2022 |
Frequently asked
Is discord.js ESM-only?
discord.js@14.27.0 ships CommonJS and ESM builds. discord.js publishes both a CommonJS entry and a native ESM entry (ESM added in 12.2.0). require("discord.js") and import "discord.js" both work on every supported Node.js version and in Bun.
Can I require discord.js?
Yes. discord.js ships a CommonJS entry, so require("discord.js") works on every Node.js version, alongside the native ESM entry for import.
Does discord.js work in Bun?
Yes. import "discord.js" loaded successfully in Bun 1.4 on Sep 9, 2026.
Does discord.js ship TypeScript types?
Yes. discord.js 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
- optimize-css-assets-webpack-plugin 6.0.1CommonJS
- replace-in-file 9.0.0ESM-only
- stylus-loader 9.0.0Dual
- node-uuid 1.4.8CommonJS
- shortid 2.2.17CommonJS
- gulp-util 3.0.8CommonJS
- istanbul 0.4.5CommonJS
- postcss-url 10.1.4CommonJS