Code Monkey home page Code Monkey logo

Comments (6)

codetheweb avatar codetheweb commented on June 11, 2024 2

Since it seems several other people are having this issue as well, would it be possible to add a workaround for now and then perhaps look at other options later (I assume those would take longer than adding a few config lines)?

from voice.

RealAlphabet avatar RealAlphabet commented on June 11, 2024 1

I found a rather elegant solution to avoid modifying all your code to CJS.
This way NodeJS will load the CJS version of @discordjs/voice instead of ESM.

import { createRequire } from "module";

const {
    joinVoiceChannel,
    createAudioPlayer,
    createAudioResource,
    entersState,
    VoiceConnectionStatus,
    NoSubscriberBehavior,
} = createRequire(import.meta.url)("@discordjs/voice");

@codetheweb

from voice.

MrPropre avatar MrPropre commented on June 11, 2024

This is related to this issue with esbuild evanw/esbuild#946

Affected files are:
https://github.com/discordjs/voice/blob/main/src/util/generateDependencyReport.ts
https://github.com/discordjs/voice/blob/main/src/util/Secretbox.ts
These files use require which is not defined in es module scope. But esbuild should have created the require function in this case.

There is a workaround described in the esbuild issue but maybe we should consider migrating to dynamic import syntax or reading and parsing json files manually

from voice.

RealAlphabet avatar RealAlphabet commented on June 11, 2024

Same here on Linux (Debian 10 Buster).

from voice.

fredkilbourn avatar fredkilbourn commented on June 11, 2024

Is this a workaround in your build or a workaround we're expected to run in our environment?

from voice.

RealAlphabet avatar RealAlphabet commented on June 11, 2024

Let me reopen this issue to notify of a strange behavior that may occur when using createRequire.
https://nodejs.org/api/packages.html#dual-package-hazard

Just to be sure, this should remain a temporary solution until the problem is fixed on esbuild.
Otherwise we should find another solution to load the dependencies.

from voice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.