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

[Bug] esbuild-plugin-pnp does not respect browser-specific exports #2987

Closed
1 task done
SteffeyDev opened this issue Jun 4, 2021 · 3 comments
Closed
1 task done
Labels
bug Something isn't working upholded Real issues without formal reproduction

Comments

@SteffeyDev
Copy link

  • I'd be willing to implement a fix

Describe the bug

Trying to use uuid library with esbuild, and using yarn berry with PNP, so esbuild-plugin-pnp is needed. The uuid library has different exports for browser vs node, and I set esbuild's platform to browser, but the plugin is causing it to ignore the browser export and bundle the node version instead. This results in esbuild exporting a browser bundle that relies on a node built-in, which can't run in the browser.

To Reproduce

See https://github.com/SteffeyDev/eslint-pnp-bug-reproduction

I setup two identical projects using uuid. The only difference between the two is one uses yarn berry, and one uses yarn classic. With yarn classic, everything works as expected, and the out.js file contains the browser version of the code. With yarn berry, it uses the node version of the code and the out.js file is much longer. Given both projects have the same input file and the same esbuild config, I would expect the outputs to be the same, but they are much different.

Environment if relevant (please complete the following information):

  • OS: Linux
  • Node version v14.16.0
  • Yarn version 1.22.4 and 2.4.2

Additional context

I love PNP and use it for a large project at my company. However, when trying to switch to esbuild for better performance, I ran into these issues, forcing me back to webpack/rollup. Would love to see this (I assume fairly common) setup support so that esbuild can continue being used and grown.

@SteffeyDev SteffeyDev added the bug Something isn't working label Jun 4, 2021
@merceyz merceyz added the upholded Real issues without formal reproduction label Jun 4, 2021
@SamChou19815
Copy link
Contributor

Related #2815

@swandir
Copy link
Contributor

swandir commented Oct 28, 2021

pnpapi used by @yarnpkg/esbuild-plugin-pnp doesn't seem to support options to enable module & browser field handling.

Meanwhile enhanced-resolve supports both pnp and module, browser, exports fields. So I made a little esbuild plugin based on it (github, npm).

It seems to work with packages that have tricky module mapping, though I've tested only a few.

@merceyz
Copy link
Member

merceyz commented Sep 2, 2022

Native support for PnP was added to esbuild@0.15.0 so @yarnpkg/esbuild-plugin-pnp is no longer required and is getting deprecated, if you experience any issues with the PnP support in esbuild please report them upstream.

@merceyz merceyz closed this as not planned Won't fix, can't repro, duplicate, stale Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upholded Real issues without formal reproduction
Projects
None yet
Development

No branches or pull requests

4 participants