Skip to content

Preload Yarn PnP and add autolinking fallback in Podfile - #53723

Open
hyochan wants to merge 5 commits into
react:mainfrom
hyochan:template/ios-pnp-preload-autolink-fallback
Open

Preload Yarn PnP and add autolinking fallback in Podfile#53723
hyochan wants to merge 5 commits into
react:mainfrom
hyochan:template/ios-pnp-preload-autolink-fallback

Conversation

@hyochan

@hyochan hyochan commented Sep 10, 2025

Copy link
Copy Markdown
Contributor

Changelog:

[iOS] [Fixed] - Fix autolinking under Yarn PnP in the HelloWorld Podfile.

Summary

Make the HelloWorld iOS Podfile robust under Yarn 3 Plug’n’Play by preloading PnP and adding a safe fallback.

Test Plan

  • PnP: init new app → set Yarn Berry + nodeLinker pnp → yarn installnpx pod-install → codegen runs, Pods generated, no "react_native_pods.rb" error, iOS build OK.
  • Non-PnP: init new app → yarn install (or npm i) → npx pod-install → behavior unchanged.

Summary:
- Preload .pnp.cjs via NODE_OPTIONS so Node resolves RN scripts under Yarn PnP during [!] No `Podfile' found in the project directory..
- Wrap  with a safe fallback that derives  from  when CLI config fails.

Motivation:
CocoaPods executes Node without Yarn PnP hooks, causing failures like:
- Cannot find module
- Autolinking exit advising to install
This change makes the iOS template resilient in PnP and non-standard setups.

Behavior:
- No-op on non-PnP projects (gated by existence of ).
- Preserves default behavior when CLI config works.

Test Plan:
1) Yarn 3 PnP app from template: yarn install v1.22.22
[1/4] Resolving packages...
[2/4] Fetching packages...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. succeeds; Codegen runs; Pods project generates.
2) Non-PnP app:  absent; [!] No `Podfile' found in the project directory. behavior unchanged.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 10, 2025
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Sep 10, 2025
@hyochan
hyochan force-pushed the template/ios-pnp-preload-autolink-fallback branch from 6e5debc to aa88314 Compare September 10, 2025 23:47
@hyochan
hyochan force-pushed the template/ios-pnp-preload-autolink-fallback branch from 027045c to 10cc23a Compare September 11, 2025 01:09
@hyochan

hyochan commented Sep 11, 2025

Copy link
Copy Markdown
Contributor Author

Because Danger CI kept failing on the changelog format (even though it was written correctly), I decided to keep the PR description short for now.
Below, I’ve re-included the original detailed explanation and screenshots as an addendum for reviewers’ reference.

Preload Yarn PnP runtime and add a safe fallback for use_native_modules! to make the iOS template resilient under non-standard setups (e.g., Yarn 3 PnP).

  • Preload .pnp.cjs via NODE_OPTIONS during pod install so Node can resolve React Native CLI scripts when CocoaPods spawns Node without Yarn PnP hooks.
  • Wrap use_native_modules! with a fallback that derives reactNativePath from require.resolve('react-native/package.json') when CLI config lookup fails.
  • Execute config.sh with bash (not sh) to match the script’s shebang and ensure compatibility on macOS/CI.

Motivation: CocoaPods invokes Node without Yarn PnP hooks, which leads to failures such as:

  • Cannot find module 'react-native/scripts/react_native_pods.rb'
  • Autolinking terminating early with advice to install @react-native-community/cli

This change is a no-op for non-PnP projects and preserves default behavior when CLI config resolution succeeds.


Test Plan

PnP project (Yarn 3, Plug’n’Play)

npx @react-native-community/cli@latest init AwesomeProject
cd AwesomeProject
corepack enable (if needed)
yarn set version berry (if not already on Yarn 3)
yarn config set nodeLinker pnp
yarn install
npx pod-install

Validate:

  • ✅ Codegen runs
  • ✅ Pods project is generated successfully
  • ✅ No “Cannot find module …/react_native_pods.rb”
  • ✅ iOS build succeeds (ios/AwesomeProject.xcworkspace)

Non-PnP project (classic node_modules)

npx @react-native-community/cli@latest init AwesomeProject
cd AwesomeProject
yarn install   # or npm i
npx pod-install

Validate:

  • ✅ Behavior unchanged from today
  • ✅ Template continues to work as before

Additional checks from this repo’s HelloWorld

  • ruby -c private/helloworld/ios/Podfile → syntax OK

  • bundle exec pod install in private/helloworld/ios:

    • Preflight runs; on failure, it cleanly falls back to minimal config (no autolinking) without exiting.
    • RN codegen artifacts (ReactCodegen, ReactAppDependencyProvider) are generated.

Behavioral Guarantees

  • Gated by presence of .pnp.cjs → no-op on non-PnP setups.
  • When CLI config works, the fallback is not used.
  • When CLI config fails, fallback via require.resolve('react-native/package.json') unblocks autolinking/Pods.

Screenshots

Without this patch Screenshot 2025-09-11 at 5 40 14 AM

With this patch Screenshot 2025-09-11 at 5 39 21 AM

Removed the nonessential YARN_IGNORE_ENGINES line to keep the change minimal.
@hyochan

hyochan commented Sep 11, 2025

Copy link
Copy Markdown
Contributor Author

https://github.com/facebook/react-native/actions/runs/17631368517/job/50099276962?pr=53723 The failure doesn't seem to be related to current PR!

@react-native-bot

Copy link
Copy Markdown
Collaborator

This PR is stale because it has been open for 180 days with no activity. It will be closed in 7 days unless you comment on it or remove the "Stale" label.

@react-native-bot react-native-bot added Stale There has been a lack of activity on this issue and it may be closed soon. and removed Stale There has been a lack of activity on this issue and it may be closed soon. labels Mar 10, 2026
@react-native-bot

Copy link
Copy Markdown
Collaborator

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@react-native-bot react-native-bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. Stale There has been a lack of activity on this issue and it may be closed soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants