canirequire

canirequireDual (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.

Latest
14.27.0 (Jul 15, 2026)
Module format
Dual (CommonJS + ESM)
Last CommonJS version
14.27.0
Native ESM since
12.2.0
TypeScript types
Bundled
Node engines
>=18
Weekly downloads
978K
License
Apache-2.0

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.

Runtimerequire("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).

VersionsFormatFirst published
14.15.0 – 14.27.0Dual (CommonJS + ESM)May 4, 2024
14.0.1 – 14.14.1CommonJSJul 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

Similar popularity