repack icon indicating copy to clipboard operation
repack copied to clipboard

fix: add `react-native` to `byDependency`

Open tringenbach opened this issue 6 months ago • 5 comments

Summary

Add react-native to byDependency in getResolveOptions. This fixes an issue with importing react-strict-dom when enablePackageExports is on. (Turning on enablePackageExports is what react-strict-dom recommends, and is the new metro default.)

Fixes #1183. There's additional discussion there.

Test plan

tringenbach avatar Jun 24 '25 00:06 tringenbach

🦋 Changeset detected

Latest commit: 635f06b24b024d8ea179dce73d4e9f3aafddf543

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@callstack/repack Patch
@callstack/repack-plugin-expo-modules Patch
@callstack/repack-plugin-nativewind Patch
@callstack/repack-plugin-reanimated Patch
@callstack/repack-dev-server Patch
@callstack/repack-init Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Jun 24 '25 00:06 changeset-bot[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
repack-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 23, 2025 0:12am

vercel[bot] avatar Jun 24 '25 00:06 vercel[bot]

looks like the resolver compat tests are also failing

jbroma avatar Jun 24 '25 08:06 jbroma

looks like the resolver compat tests are also failing

Whoops. I'll try to get this fixed.

Looks like they're related to the "web" platform:

    ● with package exports resolution enabled › conditional exports › unstable_conditionsByPlatform › should resolve "browser" condition for `web` platform when configured

Anything I should know around that? I don't see a lot of platform web code in there already. Should I use preferNativePlatform, or _platform or some combination of those?

tringenbach avatar Jun 24 '25 14:06 tringenbach

looks like the resolver compat tests are also failing

Whoops. I'll try to get this fixed.

Looks like they're related to the "web" platform:

    ● with package exports resolution enabled › conditional exports › unstable_conditionsByPlatform › should resolve "browser" condition for `web` platform when configured

Anything I should know around that? I don't see a lot of platform web code in there already. Should I use preferNativePlatform, or _platform or some combination of those?

I've had a look at the tests and it looks like it's just a matter of a setup - the tests were failing because react-native condition was injected in places where it shouldn't have been.

in tests/metro-compat/resolver/resolve.ts change the following:

diff --git a/tests/metro-compat/resolver/resolve.ts b/tests/metro-compat/resolver/resolve.ts
index 1b3c105d1..064b07081 100644
--- a/tests/metro-compat/resolver/resolve.ts
+++ b/tests/metro-compat/resolver/resolve.ts
@@ -149,13 +149,9 @@ export function resolve(
   // this is equivalent to "byDependency" configuration in rspack/webpack
   // enhanced-resolve does not use "byDependency" configuration
   if (metroContext.isESMImport) {
-    resolveOptions.conditionNames?.push(
-      ...resolutionPreset.byDependency.esm.conditionNames
-    );
+    resolveOptions.conditionNames?.push('import');
   } else {
-    resolveOptions.conditionNames?.push(
-      ...resolutionPreset.byDependency.commonjs.conditionNames
-    );
+    resolveOptions.conditionNames?.push('require');
   }
 
   const resolve = enhancedResolve.create.sync(resolveOptions);

jbroma avatar Jun 24 '25 21:06 jbroma

in tests/metro-compat/resolver/resolve.ts change the following:

Ok, I applied your fix, thanks!

I was trying to understand if that was really good enough or not, but I guess it is. Should I also be adding a test somewhere for this case, since I don't think anything existing is covering it?

tringenbach avatar Jun 26 '25 01:06 tringenbach

in tests/metro-compat/resolver/resolve.ts change the following:

Ok, I applied your fix, thanks!

I was trying to understand if that was really good enough or not, but I guess it is. Should I also be adding a test somewhere for this case, since I don't think anything existing is covering it?

hey, sorry for my delayed reply

I've been working on setting up resolver cases test package along side existing metro compat tests, I'll try to get that merged and you will be able to add a test case there that will cover it 👍

jbroma avatar Jun 29 '25 12:06 jbroma

@tringenbach please update the branch with newest main and then you can adjust the newly added resolver test cases which this PR fixes. The tests are already there so just removing .fails should do it :) (unless you want to add some more, then feel free to do so!)

jbroma avatar Jun 29 '25 13:06 jbroma

@tringenbach let me know if you need clarification on something if needed, happy to help and drive this to the end 👍

jbroma avatar Jul 02 '25 13:07 jbroma

@tringenbach please update the branch with newest main and then you can adjust the newly added resolver test cases which this PR fixes. The tests are already there so just removing .fails should do it :) (unless you want to add some more, then feel free to do so!)

Sorry, somehow I missed this message. I'll do that!

tringenbach avatar Jul 02 '25 14:07 tringenbach

@tringenbach thank you for your work on this 🚀

jbroma avatar Jul 23 '25 12:07 jbroma