facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.25k stars 626 forks source link

Package exports: resolve to real paths, fix module duplication in output #1198

Closed robhogan closed 10 months ago

robhogan commented 10 months ago

Summary: Fix: https://github.com/facebook/metro/issues/1197

unstable_enablePackageExports and unstable_enableSymlinks in combination may result in non-real module paths in the graph, because PackageExportsResolve only uses context.doesFileExist and does not necessarily return real paths.

Often, especially with pnpm, this results in a module appearing multiple times under different paths in the output bundle, as if duplicated on the file system, which causes incorrect behaviour for stateful modules and increases bundle size.

The fix mirrors the implementation of resolveSourceFileForExt in the non-exports resolver.

Changelog:

 - **[Experimental]:** Fix module duplication due to non-real resolved paths when combining `unstable_enablePackageExports` and `unstable_enableSymlinks`.

Differential Revision: D52964393

facebook-github-bot commented 10 months ago

This pull request was exported from Phabricator. Differential Revision: D52964393

facebook-github-bot commented 10 months ago

This pull request has been merged in facebook/metro@98b05c2767cb62e2420c2c88b3af7c6612ec5dd6.