Skip to content

Commit 7185e9a

Browse files
Saadnajmiclaude
andcommitted
fix(0.81): use --install-links to avoid module instance duplication
npm install <local-path> creates a symlink, causing Node to follow the real path back to the monorepo for module resolution. This means bundle.js loads @react-native/metro-config from the monorepo while the user's metro.config.js loads it from the test project's node_modules — two different instances. setFrameworkDefaults() (which registers the "macos" platform) targets the monorepo's instance, so the test project never sees it and xcodebuild fails with "Invalid platform macos". Using --install-links copies the package files instead, so all require() calls resolve from a single node_modules tree. Also removes debug steps that are no longer needed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ae13779 commit 7185e9a

1 file changed

Lines changed: 10 additions & 23 deletions

File tree

.github/workflows/microsoft-test-react-native-macos-init.yml

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,8 @@ jobs:
2929
run: |
3030
yarn build
3131
# yarn build rewrites package.json "exports" from ./src to ./dist
32-
# for publishing. The dist/ files use ESM syntax that requires
33-
# babel-register (only wired up in src/index.js). When the test
34-
# project loads react-native-macos as a dependency via symlink,
35-
# require('@react-native/community-cli-plugin') resolves to
36-
# dist/index.js which fails to load, silently preventing the
37-
# macos platform from being registered. Restore src exports so
38-
# the monorepo's babel-register entry point is used.
32+
# for publishing. Restore the original exports so that any
33+
# monorepo tooling that still runs from source continues to work.
3934
git checkout -- packages/*/package.json
4035
4136
- name: Build react-native-macos-init
@@ -61,7 +56,14 @@ jobs:
6156
working-directory: ${{ runner.temp }}/testcli
6257
run: |
6358
set -eox pipefail
64-
npm install ${{ github.workspace }}/packages/react-native
59+
# --install-links copies the package instead of symlinking it.
60+
# Without this, Node follows the symlink's real path back to the
61+
# monorepo for module resolution, causing bundle.js to load a
62+
# different instance of @react-native/metro-config than the one
63+
# the user's metro.config.js uses. The setFrameworkDefaults()
64+
# call (which registers the "macos" platform) then targets the
65+
# wrong instance, and xcodebuild fails with "Invalid platform".
66+
npm install --install-links ${{ github.workspace }}/packages/react-native
6567
6668
- name: Apply macOS template
6769
working-directory: ${{ runner.temp }}/testcli
@@ -70,21 +72,6 @@ jobs:
7072
node ${{ github.workspace }}/packages/react-native-macos-init/bin.js --verbose --overwrite --prerelease
7173
pod install --project-directory=macos
7274
73-
- name: Debug config
74-
working-directory: ${{ runner.temp }}/testcli
75-
run: |
76-
set -eox pipefail
77-
echo "=== node_modules/react-native-macos symlink ==="
78-
ls -la node_modules/react-native-macos
79-
echo "=== community-cli-plugin exports ==="
80-
node -e "console.log(require('${{ github.workspace }}/packages/community-cli-plugin/package.json').exports)"
81-
echo "=== community-cli-plugin resolve ==="
82-
node -e "console.log(require.resolve('@react-native/community-cli-plugin', {paths: [require.resolve('react-native-macos')]}))"
83-
echo "=== cli.js config platforms ==="
84-
node node_modules/react-native-macos/cli.js config 2>&1 | node -e "const d=JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')); console.log('platforms:', Object.keys(d.platforms))"
85-
echo "=== direct config load ==="
86-
node -e "process.chdir('${{ runner.temp }}/testcli'); const c = require('${{ github.workspace }}/packages/react-native/react-native.config.js'); console.log('platforms:', Object.keys(c.platforms))"
87-
8875
- name: Build macOS app
8976
working-directory: ${{ runner.temp }}/testcli
9077
run: |

0 commit comments

Comments
 (0)