Metro: Support for resolving Yarn Plug 'n Play modules

Created on 6 Nov 2018  路  9Comments  路  Source: facebook/metro

Do you want to request a feature or report a bug?
Request a feature

What is the current behavior?
Metro does not (yet) have PnP support

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.

What is the expected behavior?
I think it would be very handy if Metro had support for resolving Yarn PnP modules.

Not only would there be the benefits you'd get for using it in other project, I believe that if this Yarn feature request is able to be resolved, this could be a reasonable alternative to using symlinks (since they are not able to be supported for technical reasons)

Most helpful comment

@arlyon I just added an example repo with pnp and react native working. Checkout the metro.config.js here: https://github.com/dalinarkholin/react-native-pnp-enabled

Also my comment here: https://github.com/react-native-community/cli/issues/27#issuecomment-625912523

But yes, it would be good to get it back as a option as well :)

All 9 comments

It actually already does! We just need to open-source the resolver in a separate package (or make it native, possible) 馃槂 ping @rafeca

Curious how this is going. If the internal resolver is inappropriate for open source, perhaps I could make an attempt at implementing one.

I think this could probably be a first-class metro feature. Only thing I can't really figure out is a good way to unit test it. Non-PnP mode has really nice virtual filesystem for testing, and this wouldn't be able to make use of that without heavy modification (probably)

@arcanis @empyrical was Pnp support removed? Im guessing that is why this is still open?

Yep, I think FB removed it about a year ago since they don't use it internally. You should be able to add it back by overriding resolveRequest in your configuration, though.

Now that yarn uses pnp by default, can we consider adding it again?

@arlyon I just added an example repo with pnp and react native working. Checkout the metro.config.js here: https://github.com/dalinarkholin/react-native-pnp-enabled

Also my comment here: https://github.com/react-native-community/cli/issues/27#issuecomment-625912523

But yes, it would be good to get it back as a option as well :)

Would it help if I provide a pull request to get this back in? If there is no interest in adding this back in we could create a separate package for it so that at least React Native has a way forward for adopting Yarn 2.

Would it help if I provide a pull request to get this back in? If there is no interest in adding this back in we could create a separate package for it so that at least React Native has a way forward for adopting Yarn 2.

I'd love to see this either way, but would use a separate package if metro isn't interested in adding it.

Was this page helpful?
0 / 5 - 0 ratings