fix(init): Fix yarn + skip-install combo causing template copy failure #2748
+61
−21
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.
Summary
This PR fixes a bug where specifying
--pm yarntogether with--skip-installcaused the init command to fail during template copying. The issue occurred because yarn configuration commands were not being awaited before installing the template package, creating a race condition wherenode_moduleswasn't fully created before template copying attempted to accesstemplate.config.js.closes #2743
Additionally, this PR fixes an issue where
require.resolve('react-native')was being called even when--install-pods false, causing failures with custom templates that don't include react-native.Reproducible demo:
Error before fix:
Test Plan
Added e2e test: Created
init supports --pm yarn together with --skip-installtest case that verifies the combination works correctlyUpdated test expectations: Modified test to account for Yarn 2+ configuration files (
.yarn,.yarnrc.yml) that are created when using yarnManual verification: Tested the exact command from the bug report:
This now completes successfully without errors.
Regression testing: Verified that:
--pm yarnwithout--skip-installstill works--pm npmwith--skip-installstill works--pm bunwith--skip-installstill works--install-pods falseno longer fail with react-native resolution errorsChanges made:
packages/cli/src/commands/init/template.ts: Addedawaitto yarn configexecuteCommandcalls to ensure they complete before template installationpackages/cli/src/commands/init/init.ts: Movedrequire.resolve('react-native')inside conditional blocks so it only runs when CocoaPods installation is requested__e2e__/init.test.ts: Added test case and updated file expectations for Yarn 2+ config filesChecklist
react-nativecheckout (instructions).