You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My project uses pnpm + monorepo + react-native, and other self-developed libraries.
In my example project, I have three sub-projects, of which tool-demo is the react-native project, tool-runtime and tool-utils are other function libraries.
In the metro.config.js, unstable_enablePackageExports and unstable_enableSymlinks are true.
The dependencies are like this:
tool-demo use tool-utils
tool-utils uses tool-runtime/index and tool-runtime/setget.
tool-runtime/index also uses tool-runtime/setget
When I bundle the react-native project,the code of tool-runtime/setget has been bundled twice.
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.
cd packages/tool-demo and pnpm run build:ios, then will output the index.bundle.ios.js in the tool-demo dir.
search the keyword console.log('setRuntimeHelper'); in the index.bundle.ios.js, will find that the code is duplicated.
This will cause files with different paths to reference tool-runtime/setget will get different code values, like the let number in tool-runtime/setget.
What is the expected behavior?
No duplicate bundled code.
Now I use resolveRequest to solve this question. For details, please view the commented code below in the metro.config.js
Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.
The text was updated successfully, but these errors were encountered:
orochi97
changed the title
[0.80.4] Metro bundle duplicate code when use unstable_enablePackageExports and unstable_enableSymlinks
[0.80.4] Metro bundle duplicated code when use unstable_enablePackageExports and unstable_enableSymlinks
Jan 20, 2024
Huge thanks @orochi97 for the detailed report and repro - confirmed this is a previously-unknown bug due to a non-real absolute path ending up in the dependency graph, which shouldn't happen.
I'm looking into this now - in the mean time your commented out realPathSync custom resolver looks like a good workaround.
robhogan
added a commit
to robhogan/metro
that referenced
this issue
Jan 22, 2024
Summary:
Fix: facebook#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
This turned out to be an issue with the package exports resolver, and the fix also ended up reducing bundle size by ~5% in the case of your demo. Thanks again for the report.
Do you want to request a feature or report a bug?
bug
What is the current behavior?
My project uses
pnpm
+monorepo
+react-native
, and other self-developed libraries.In my example project, I have three sub-projects, of which tool-demo is the react-native project, tool-runtime and tool-utils are other function libraries.
In the metro.config.js, unstable_enablePackageExports and unstable_enableSymlinks are true.
The dependencies are like this:
When I bundle the react-native project,the code of tool-runtime/setget has been bundled twice.
If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can
yarn install
andyarn test
.Here is my example project: https://github.com/orochi97/monorepo/tree/main
steps:
pnpm install
cd packages/tool-demo
andpnpm run build:ios
, then will output theindex.bundle.ios.js
in the tool-demo dir.console.log('setRuntimeHelper');
in theindex.bundle.ios.js
, will find that the code is duplicated.This will cause files with different paths to reference tool-runtime/setget will get different code values, like the
let number
in tool-runtime/setget.What is the expected behavior?
No duplicate bundled code.
Now I use
resolveRequest
to solve this question. For details, please view the commented code below in the metro.config.jsPlease provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.
npx react-native info
Looking forward to reply, thank you :)
The text was updated successfully, but these errors were encountered: