Search code examples
discord.jspnpm

@discordjs/voice can't find encryption package with pnpm


When I try to play audio with @discordjs/voice I just get an error:

 ERROR  file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/@discordjs+voice@0.13.0_@discordjs+opus@0.9.0/node_modules/@discordjs/voice/src/util/Secretbox.ts:51
        throw new Error(
       ^


 ERROR  Error: Cannot play audio as no valid encryption package is installed.                                 20:03:27
- Install sodium, libsodium-wrappers, or tweetnacl.
- Use the generateDependencyReport() function for more information.

    at Object.fallbackError (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/@discordjs+voice@0.13.0_@discordjs+opus@0.9.0/node_modules/@discordjs/voice/src/util/Secretbox.ts:51:8)
    at Networking.encryptOpusPacket (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/@discordjs+voice@0.13.0_@discordjs+opus@0.9.0/node_modules/@discordjs/voice/src/networking/Networking.ts:585:23)
    at Networking.createAudioPacket (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/@discordjs+voice@0.13.0_@discordjs+opus@0.9.0/node_modules/@discordjs/voice/src/networking/Networking.ts:568:47)
    at Networking.prepareAudioPacket (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/@discordjs+voice@0.13.0_@discordjs+opus@0.9.0/node_modules/@discordjs/voice/src/networking/Networking.ts:490:31)
    at VoiceConnection.prepareAudioPacket (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/@discordjs+voice@0.13.0_@discordjs+opus@0.9.0/node_modules/@discordjs/voice/src/VoiceConnection.ts:520:27)
    at AudioPlayer._preparePacket (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/@discordjs+voice@0.13.0_@discordjs+opus@0.9.0/node_modules/@discordjs/voice/src/audio/AudioPlayer.ts:640:15)
    at AudioPlayer._stepPrepare (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/@discordjs+voice@0.13.0_@discordjs+opus@0.9.0/node_modules/@discordjs/voice/src/audio/AudioPlayer.ts:604:10)
    at prepareNextAudioFrame (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/@discordjs+voice@0.13.0_@discordjs+opus@0.9.0/node_modules/@discordjs/voice/src/DataStore.ts:146:13)
    at audioCycleStep (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/@discordjs+voice@0.13.0_@discordjs+opus@0.9.0/node_modules/@discordjs/voice/src/DataStore.ts:127:2)
    at Timeout._onTimeout (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/@discordjs+voice@0.13.0_@discordjs+opus@0.9.0/node_modules/@discordjs/voice/src/DataStore.ts:139:42)

Here's the output of generateDependencyReport():

--------------------------------------------------                                                            20:11:50
Core Dependencies
- @discordjs/voice: 0.13.0
- prism-media: not found

Opus Libraries
- @discordjs/opus: not found
- opusscript: not found

Encryption Libraries
- sodium-native: not found
- sodium: not found
- libsodium-wrappers: not found
- tweetnacl: not found

FFmpeg
- version: 2021-09-08-git-5e7e2e5031-full_build-www.gyan.dev
- libopus: yes
--------------------------------------------------

These are my dependencies:

"dependencies": {
    "@discordjs/opus": "^0.9.0",
    "@discordjs/voice": "^0.13.0",
    "consola": "^2.15.3",
    "discord.js": "^14.6.0",
    "libsodium-wrappers": "^0.7.10",
    "sodium-native": "^3.4.1",
    "tweetnacl": "^1.0.3"
},

As you can see I've clearly installed an encryption package, but it's not being detected by @discordjs/voice. I believe it's because I am using pnpm, as it's node_modules format is different compared to normal npm. Does anyone know how to make @discordjs/voice detect it?


Solution

  • It is a bug with @discordjs/voice if it can't work with symlinked dependencies.

    But you can use node-linker=hoisted to install a hoisted node_modules without using symlinks. Put this setting to a .npmrc file in the root of you project, remove node_modules and run pnpm install.