fix(react-native): order react-native export condition before require#1028
Closed
kylemcd wants to merge 1 commit into
Closed
fix(react-native): order react-native export condition before require#1028kylemcd wants to merge 1 commit into
kylemcd wants to merge 1 commit into
Conversation
Metro resolves conditional exports by first match in object-key order. Because the `require` condition was listed before `react-native` in the `exports["."]` map, Metro (with package exports enabled by default since React Native 0.79) matched `require` first and resolved @knocklabs/react-native to the prebuilt `dist/cjs` bundle instead of the `react-native` -> `src/index.ts` source entry it is meant to serve. Reorder the map so `types` and `react-native` come first, matching @knocklabs/react-core and @knocklabs/client. Verified against metro-resolver: the package now resolves to `./src/index.ts` under RN's active conditions. Refs #838
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: e765e3e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1028 +/- ##
=======================================
Coverage 64.49% 64.49%
=======================================
Files 212 212
Lines 10217 10217
Branches 1389 1389
=======================================
Hits 6589 6589
Misses 3603 3603
Partials 25 25 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes the
exportsmap ordering in@knocklabs/react-nativeso React Native's Metro bundler resolves the package to its source entry point (src/index.ts) rather than the prebuiltdist/cjsbundle.Root cause. Node/Metro conditional-exports matching is first-match by object-key order. The
exports["."]map listedrequirebefore thereact-nativecondition:React Native's Metro runs with both
requireandreact-nativeconditions active, so it matchedrequirefirst and loaded the prebuilt CommonJS bundle instead of thesrc/index.tssource thereact-nativecondition exists to serve. Every sibling package (@knocklabs/client,@knocklabs/react-core,@knocklabs/react) already listsreact-nativefirst —react-nativewas the odd one out.Why it started with RN 0.79. Package-exports resolution is enabled by default in Metro since React Native 0.79. On older RN, Metro used
resolverMainFields→ the top-level"react-native": "./src/index.ts"field → source, so it worked. This lines up with #838 (Cannot read property 'KnockProvider' of undefined), reported on RN 0.79.2.Fix. Reorder
exports["."]sotypes+react-nativecome first, matching@knocklabs/react-core.Verification. Ran the real export maps through Metro's own resolver (
metro-resolver'sreduceExportsLikeMap) under RN's active conditions ({default, require, react-native}):@knocklabs/react-native../dist/cjs/index.js❌./src/index.ts✅./package.jsonsubpath./package.json./package.json(unchanged)Tracked in KNO-14075.