Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

discordjs/voice TypeScript's definition "import" causes a TypeScript compilation error #240

Open
TIRTAGT opened this issue Dec 7, 2021 · 1 comment
Labels
bug Something isn't working need repro

Comments

@TIRTAGT
Copy link

TIRTAGT commented Dec 7, 2021

Issue description

Steps to reproduce the issue :

  • Install discordjs/voice via npm

    • npm install @discordjs/voice
  • Install discordjs/opus via npm

    • npm install @discordjs/opus
  • Install sodium via npm

    • npm install sodium
  • Verify that npm had installed these version of those packages :

    • @discordjs/voice v0.7.5
    • @discordjs/opus v0.5.3
    • sodium v3.0.2
  • Create a starting point for the bot (in a src folder), could be a simple ping and pong command

  • creates tsconfig.json with these contents :

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2020",
        "jsx": "preserve",
        "strictFunctionTypes": true,
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "outDir": "./build",
        "rootDir": "./src",
        "typeRoots": [
            "./node_modules/@types",
            "./node_modules/discord.js/typings",
            "./node_modules/@discordjs/voice",
        ]
    },
    "exclude": [
		"./node_modules/@discordjs",
        "node_modules",
        "**/node_modules/*",
    ]
}

adjust the tsconfig's if you have different source and build folder.

  • Run typescript compilation

    • tsc -p tsconfig.json
  • Enjoy the error :

Module '"${ProjectPath}/node_modules/prism-media/typings/index"' has no default export.
- From : ${ProjectPath}/node_modules/@discordjs/voice/dist/index.d.ts, Line 2

Module '"${ProjectPath}/node_modules/@types/ws/index"' can only be default-imported using the 'esModuleInterop' flag
- From : ${ProjectPath}/node_modules/@discordjs/voice/dist/index.d.ts, Line 5

Code sample

${ProjectPath}/node_modules/@discordjs/voice/dist/index.d.ts, contents : 

import { Readable, ReadableOptions } from 'node:stream';
import prism from 'prism-media';
import { TypedEmitter } from 'tiny-typed-emitter';
import { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData } from 'discord-api-types/v9';
import WebSocket, {MessageEvent} from 'ws';

@discordjs/voice version

0.7.5

Node.js version

v17.2.0

Operating system

Linux, BTW I use "linux 5.15.5.arch1-1" kernel

Priority this issue should have

Medium (should be fixed soon)

@TIRTAGT TIRTAGT added bug Something isn't working need repro labels Dec 7, 2021
@TIRTAGT
Copy link
Author

TIRTAGT commented Dec 7, 2021

Temporary fix I have currently, replace the ${ProjectPath}/node_modules/@discordjs/voice/dist/index.d.ts from line 1 to 6 with these :

import { Readable, ReadableOptions } from 'node:stream';
import * as prism from 'prism-media';
import { TypedEmitter } from 'tiny-typed-emitter';
import { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData } from 'discord-api-types/v9';
import * as WebSocket from 'ws';
import { MessageEvent } from 'ws';

Differences between the original and my temporary fix :

import { Readable, ReadableOptions } from 'node:stream';
import prism from 'prism-media';      // - Original
import * as prism from 'prism-media'; // + Modified
import { TypedEmitter } from 'tiny-typed-emitter';
import { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData } from 'discord-api-types/v9';
import WebSocket, {MessageEvent} from 'ws'; // - Original
import * as WebSocket from 'ws';            // + Modified
import { MessageEvent } from 'ws';          // + Modified

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working need repro
Projects
None yet
Development

No branches or pull requests

1 participant