Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esbuild is unable to tree-shake rxjs under node platform #6856

Open
benlesh opened this issue Mar 3, 2022 Discussed in #6785 · 3 comments
Open

esbuild is unable to tree-shake rxjs under node platform #6856

benlesh opened this issue Mar 3, 2022 Discussed in #6785 · 3 comments

Comments

@benlesh
Copy link
Member

benlesh commented Mar 3, 2022

Discussed in #6785

Originally posted by Conaclos January 28, 2022
Hi!

I discovered that esbuild is not able to tree-shake rxjs package when bundling under node platform.
esbuild priorizes exports condition 'node' over main-fields.

Demonstration

$ cat index.js
export { Subject } from 'rxjs'

$ esbuild --bundle index.js --platform=node | wc -l
9654

$ # Specifying main-fields does not change the output
$ esbuild --bundle index.js --platform=node --main-fields=es2015,module,main | wc -l
9654

$ # browser bundle is lighter
$ esbuild --bundle index.js --platform=browser | wc -l
1161

Note that we need to bundle for node since our project and most of our dependencies imports node-specific modules.

How to solve the issue?

rxjs should not use the condition "node".
It should use the condition "require":

  ...
  "exports": {
    ".": {
      "require": "./dist/cjs/index.js",
      "es2015": ...,
      "default": ...
    },
    ....

instead of:

  ...
  "exports": {
    ".": {
      "node": "./dist/cjs/index.js",
      "es2015": ...,
      "default": ...
    },
    ....
```</div>
@akanass
Copy link

akanass commented Mar 7, 2022

I guess it's related to my one year issue

@benlesh
Copy link
Member Author

benlesh commented Mar 7, 2022

@akanass Yes. I know that's a "one year issue". Unfortunately, RxJS is so widely used that if we pushed out breaking changes and published new majors too often it would cause a lot of churn for everyone. That will be fixed in 8.x

@akanass
Copy link

akanass commented Mar 7, 2022

@benlesh yes I know that :) but when I saw your issue I have remembered my issue that's why I mentioned it to be sure to cover all points

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants