discordjs/discord.js · critical · Error

Cannot play audio as no valid encryption package is installe

Error message

Cannot play audio as no valid encryption package is installed.
- Install one of:
  - sodium
  - libsodium-wrappers
  - @stablelib/xchacha20poly1305
  - @noble/ciphers.
- Use the generateDependencyReport() function for more information.

What it means

Secretbox.ts lazily selects an encryption backend from the packages installed in your project (sodium, libsodium-wrappers, @stablelib/xchacha20poly1305, @noble/ciphers). If none of them are available at runtime, loading the secretbox module throws this Error telling you to install one and consult generateDependencyReport(). @discordjs/voice deliberately ships no crypto dependency, so this is a required optional peer dependency.

Source

Thrown at packages/voice/src/util/Secretbox.ts:92

		crypto_aead_xchacha20poly1305_ietf_encrypt(cipherText, additionalData, nonce, key) {
			const crypto = new stablelib.XChaCha20Poly1305(key);
			return crypto.seal(nonce, cipherText, additionalData);
		},
	}),
	'@noble/ciphers/chacha.js': (noble: any): Methods => ({
		crypto_aead_xchacha20poly1305_ietf_decrypt(cipherText, additionalData, nonce, key) {
			const chacha = noble.xchacha20poly1305(key, nonce, additionalData);
			return chacha.decrypt(cipherText);
		},
		crypto_aead_xchacha20poly1305_ietf_encrypt(plaintext, additionalData, nonce, key) {
			const chacha = noble.xchacha20poly1305(key, nonce, additionalData);
			return chacha.encrypt(plaintext);
		},
	}),
} as const;

const fallbackError = () => {
	throw new Error(
		`Cannot play audio as no valid encryption package is installed.
- Install one of:
  - sodium
  - libsodium-wrappers
  - @stablelib/xchacha20poly1305
  - @noble/ciphers.
- Use the generateDependencyReport() function for more information.\n`,
	);
};

const methods: Methods = {
	crypto_aead_xchacha20poly1305_ietf_encrypt: fallbackError,
	crypto_aead_xchacha20poly1305_ietf_decrypt: fallbackError,
};

// eslint-disable-next-line no-async-promise-executor
export const secretboxLoadPromise = new Promise<void>(async (resolve) => {
	for (const libName of Object.keys(libs) as (keyof typeof libs)[]) {

View on GitHub (pinned to a81ed8a306)

Solutions

  1. Install a supported encryption package: npm i @noble/ciphers (pure JS) or npm i libsodium-wrappers.
  2. Run generateDependencyReport() from @discordjs/voice to confirm which crypto package the library actually resolves.
  3. Rebuild/reinstall if a native package (sodium) failed to compile — check node-gyp/python/make toolchain, or switch to the pure-JS @noble/ciphers.
  4. If using pnpm/monorepos, add the crypto package as a direct dependency of the workspace that depends on @discordjs/voice.

Example fix

// before
import { joinVoiceChannel } from '@discordjs/voice'; // throws: no encryption package
// after
// npm i @noble/ciphers
import { joinVoiceChannel } from '@discordjs/voice'; // resolves @noble/ciphers backend
Defensive patterns

Strategy: validation

Validate before calling

// Run once at startup, before joining any channel:
import { generateDependencyReport } from '@discordjs/voice';
console.log(generateDependencyReport());
// Or programmatically fail fast:
let hasCrypto = false;
try { require.resolve('libsodium-wrappers'); hasCrypto = true; } catch {}
try { require.resolve('@noble/ciphers'); hasCrypto = true; } catch {}
if (!hasCrypto) throw new Error('Install a crypto package for @discordjs/voice (e.g. npm i libsodium-wrappers)');

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Importing/starting any audio playback (@discordjs/voice loaded, playAudio/createAudioPacket path) in a project where none of the four supported encryption packages is installed — e.g. a bare `npm i @discordjs/voice` install, pnpm's strict node_modules hiding transitive deps, or monorepos where the dep is in another workspace.

Common situations: Fresh project setups following old tutorials; Docker images pruned with --omit=optional; pnpm/yarn PnP strict dependency resolution; CI environments missing the native sodium build toolchain so installation silently failed.

Related errors


AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30). Data as JSON: /api/errors/50b28dc3042d8d27. Report an issue: GitHub.