discordjs / opus

Native opus bindings for node
MIT License
192 stars 55 forks source link

[Bun] Cannot find module "@discordjs/opus/prebuild/node-v115-napi-v3-linux-x64-glibc-2.29/opus.node" #154

Open quangpao opened 5 months ago

quangpao commented 5 months ago

Issue description

I can't use the package while using "Bun", which said to compatibility with Node.js v20.

I think Bun currently using node-v115-napi-v3-${OS}-glibc-2.29 as it primary. If this is the case, can we support this into the package?

Step to reproduce:

  1. Install @discordjs/opus:0.9.0 by command bun add @discordjs/opus
  2. Execute the function that using the @discordjs/opus
  3. Error pop-up:
    See: https://distube.js.org/classes/DisTube.html#error and https://nodejs.org/api/events.html#events_error_events
    [I] [InepEvents] Triggered |interactionCreate| event
    7 |       return data;
    8 |     } catch (e) {
    9 |       errorLog.push(e);
    10 |     }
    11 |   }
    12 |   throw new Error(errorLog.join('\n'));
              ^
    PlayingError: ResolveMessage: Cannot find module "/app/node_modules/@discordjs/opus/prebuild/node-v115-napi-v3-linux-x64-glibc-2.29/opus.node" from "/app/node_modules/@discordjs/opus/lib/index.js"
    ResolveMessage: Cannot find package "node-opus" from "/app/node_modules/prism-media/src/util/loader.js"
    ResolveMessage: Cannot find package "opusscript" from "/app/node_modules/prism-media/src/util/loader.js"

Code sample

execute: async (interaction, client?: InepClient) => {
    const member = interaction.member as GuildMember;
    const channel = member.voice.channel;

    try {
      const query = interaction.options.getString("song", true);
      const distube = client?.distube as InepTube;

      await interaction.reply({
        content: `🎵 Searching for \`${query}\`...`,
        ephemeral: true,
      });
      //This is where the error occured
      await distube.play(channel as VoiceBasedChannel, query, {
        textChannel: interaction.channel as GuildTextBasedChannel,
        member,
      });
    } catch (error) {
      logger.error(error);
    }
  },
# OVEN - BUN Official Image
FROM oven/bun:slim as base
WORKDIR /app
RUN apt-get update && apt-get install -y \
    build-essential \
    libtool \
    automake \
    python3 \
    ffmpeg \
    curl \
    && rm -rf /var/lib/apt/lists/*

RUN curl -fsSL https://deb.nodesource.com/setup_19.x | bash -
RUN apt-get install -y nodejs
# Install dependencies to temp directory
FROM base as build

# Dev dependencies 
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install

# Copy node_modules from temp directory to app directory
FROM base as prerelease
COPY --from=build /temp/dev/node_modules node_modules
COPY . .

# Copy the app to the final image
FROM base as release
COPY --from=build /temp/dev/node_modules node_modules
COPY --from=prerelease /app/src/app.ts src/app.ts
COPY --from=prerelease /app/package.json package.json

# USER bun
ENTRYPOINT [ "bun", "run", "dev" ]

Versions

Issue priority

Medium (should be fixed soon)

spjoes commented 3 months ago

Having this same issue. Would love if it could be fixed!

AceLikesGhosts commented 3 months ago

Can repro on Bun 1.1.17

vladfrangu commented 2 months ago

Can you get us a minimum repro sample with bun? Also, make sure @discordjs/opus is trusted in bun (so postinstall scripts run and actually load the appropriate binary files)

mrjeanp commented 2 months ago

Can you get us a minimum repro sample with bun? Also, make sure @discordjs/opus is trusted in bun (so postinstall scripts run and actually load the appropriate binary files)

☝️

as @vladfrangu mentioned, make sure you add @discordjs/opus to your trustedDependencies in package.json.

Also make sure you have these dependencies in your system

build-essential     libtool     automake     python3  ffmpeg

I was facing the same issue with bun.