discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.5k stars 3.97k forks source link

Errors after building with tsup #9991

Closed nicoduesing closed 1 year ago

nicoduesing commented 1 year ago

Which package is this bug report for?

discord.js

Issue description

The following error is shown on running the index.ts after building with tsup:

/dist/index.js:43253
    var __name = (target, value) => __defProp2(target, "name", { value, configurable: true });
                                    ^

TypeError: Object.defineProperty called on non-object
    at defineProperty (<anonymous>)
    at __name (/dist/index.js:43253:37)
    at <static_initializer> (/dist/index.js:43322:9)
    at node_modules/@discordjs/ws/dist/index.js (/dist/index.js:43316:41)
    at __require (/dist/index.js:32:50)
    at node_modules/discord.js/src/client/websocket/WebSocketManager.js (/dist/index.js:45421:9)
    at __require (/dist/index.js:32:50)
    at node_modules/discord.js/src/client/Client.js (/dist/index.js:49105:28)
    at __require (/dist/index.js:32:50)
    at node_modules/discord.js/src/index.js (/dist/index.js:50144:23)

Node.js v20.8.0

To reproduce this bug, create a project like the following:

The content of the files is the following: index.ts:

import { Client, GatewayIntentBits } from "discord.js";
const client = new Client({ intents: [] });

package.json:

{
  "name": "discordbug",
  "scripts": {
    "build": "tsup index.ts",
  },
  "dependencies": {
    "discord.js": "14.14.1"
  },
  "devDependencies": {
    "typescript": "5.2.2",
    "tsup": "6.2.1"
  }
}

Run the following commands:

  1. yarn install
  2. yarn run build
  3. node dist/index.js

The last command returns the error above.

Code sample

import { Client, GatewayIntentBits } from "discord.js";
const client = new Client({ intents: [] });

Versions

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

No Intents

I have tested this issue on a development release

No response

Jiralite commented 1 year ago
I cannot reproduce this issue. ``` $ tsup index.ts CLI Building entry: index.ts CLI tsup v6.2.1 CLI Target: node14 CJS Build start CJS ⚡️ Build success in 13ms CJS dist/index.js 113.00 B ✨ Done in 0.50s. jiralite@Jiralites-MacBook-Pro test % node dist/index.js jiralite@Jiralites-MacBook-Pro test % ``` image

Also... tsup 6.2.1? tsup is on at least version 8 by now. At a first glance, this is probably an issue with a configuration of yours of tsup rather than this being a discord.js issue.

nicoduesing commented 1 year ago

Ah, sorry, I had an config in a parent directory, that was used. I found the problem. The error was caused by target: "node20" . I'm using tsup 6.x because newer versions changed something in the way it bundles the dependencies, so it is not allowing to bundle everything into a single file.