discordx-ts / discordx

🤖 Create a discord bot with TypeScript and Decorators!
https://discordx.js.org
Apache License 2.0
588 stars 50 forks source link

[Bug]: Broke the ESM build by merging #929 #931

Closed TeamWolfyta closed 1 year ago

TeamWolfyta commented 1 year ago

What happened?

You broke the ESM build by merging #929, ESM requires file extensions in the imports. I would revert #929 as from my understanding, You'd have to use a bundler to make use of tree-shaking, Discordx isn't bundled last I checked, It's built then published, Making the merge completely useless.

Reproduction

Install latest version (11.7.2) and try and run it.

Package

discordx

Version

Stable

Relevant log output

> my-bot@1.0.0 dev /root/projects/teamwolfyta/my-bot
> ts-node-esm src/main.ts

/root/projects/teamwolfyta/my-bot/node_modules/.pnpm/ts-node@10.9.1_cbfmry4sbbh4vatmdrsmatfg5a/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:366
    throw new ERR_MODULE_NOT_FOUND(
          ^
CustomError: Cannot find module '/root/projects/teamwolfyta/my-bot/node_modules/.pnpm/discordx@11.7.2_discord.js@14.8.0/node_modules/lodash/escapeRegExp' imported from /root/projects/teamwolfyta/my-bot/node_modules/.pnpm/discordx@11.7.2_discord.js@14.8.0/node_modules/discordx/build/esm/Client.js
    at finalizeResolution (/root/projects/teamwolfyta/my-bot/node_modules/.pnpm/ts-node@10.9.1_cbfmry4sbbh4vatmdrsmatfg5a/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:366:11)
    at moduleResolve (/root/projects/teamwolfyta/my-bot/node_modules/.pnpm/ts-node@10.9.1_cbfmry4sbbh4vatmdrsmatfg5a/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:801:10)
    at Object.defaultResolve (/root/projects/teamwolfyta/my-bot/node_modules/.pnpm/ts-node@10.9.1_cbfmry4sbbh4vatmdrsmatfg5a/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:912:11)
    at /root/projects/teamwolfyta/my-bot/node_modules/.pnpm/ts-node@10.9.1_cbfmry4sbbh4vatmdrsmatfg5a/node_modules/ts-node/src/esm.ts:218:35
    at entrypointFallback (/root/projects/teamwolfyta/my-bot/node_modules/.pnpm/ts-node@10.9.1_cbfmry4sbbh4vatmdrsmatfg5a/node_modules/ts-node/src/esm.ts:168:34)
    at /root/projects/teamwolfyta/my-bot/node_modules/.pnpm/ts-node@10.9.1_cbfmry4sbbh4vatmdrsmatfg5a/node_modules/ts-node/src/esm.ts:217:14
    at addShortCircuitFlag (/root/projects/teamwolfyta/my-bot/node_modules/.pnpm/ts-node@10.9.1_cbfmry4sbbh4vatmdrsmatfg5a/node_modules/ts-node/src/esm.ts:409:21)
    at resolve (/root/projects/teamwolfyta/my-bot/node_modules/.pnpm/ts-node@10.9.1_cbfmry4sbbh4vatmdrsmatfg5a/node_modules/ts-node/src/esm.ts:197:12)
    at resolve (/root/projects/teamwolfyta/my-bot/node_modules/.pnpm/ts-node@10.9.1_cbfmry4sbbh4vatmdrsmatfg5a/node_modules/ts-node/src/child/child-loader.ts:15:39)
    at nextResolve (node:internal/modules/esm/loader:163:28)
 ELIFECYCLE  Command failed with exit code 1.

Code of Conduct

TeamWolfyta commented 1 year ago

Anyone else having this issue, Revert to the previous version. https://www.npmjs.com/package/discordx/v/11.7.1.

ImLunaHey commented 1 year ago

You broke the ESM build by merging https://github.com/discordx-ts/discordx/pull/929, ESM requires file extensions in the imports. I would revert https://github.com/discordx-ts/discordx/pull/929 as from my understanding, You'd have to use a bundler to make use of tree-shaking, Discordx isn't bundled last I checked, It's built then published, Making the merge completely useless.

So this is incorrect.

  1. People bundling this within their own app does take advantage of tree-shaking this change alone dropped my final build by 70kb
  2. ESM does not require file extensions. The npm module you're using does.. ts-node-esm is NOT ESM. Typescript ESM is NOT ESM.