Conditional exports proposal #401
Description
Out of discussion from the last meeting I have just posted a core PR with a conditional exports proposal here - nodejs/node#29978.
This enables e.g. browser mappings in exports, as well as the ability for require()
and import
to get different modules, as mentioned by @ljharb.
Note that the feature of supporting the "require"
condition is something that we can agree to enable or not and is somewhat independent of the proposal.
An interesting consequence of the proposal was that it provides a way to do named exports for CJS packages without getting the instance hazard, as users can effectively write their own wrapper modules.
Hopefully having the proposal fleshed out and implemented allows us to properly discuss these concerns further and decide either way both on the require handling, and on whether we want to support a conditional approach like this for browser mapping or whether we want to leave this problem to userland.