Skip to content

Conversation

@azizbecha
Copy link

Summary

This PR fixes a bug where specifying --pm yarn together with --skip-install caused 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 where node_modules wasn't fully created before template copying attempted to access template.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:

npx @react-native-community/cli@latest init RN0821Test3 --skip-install --pm yarn

Error before fix:

error Couldn't find the "/var/folders/.../node_modules/@react-native-community/template/template.config.js file inside "@react-native-community/template" template.

Test Plan

  1. Added e2e test: Created init supports --pm yarn together with --skip-install test case that verifies the combination works correctly

  2. Updated test expectations: Modified test to account for Yarn 2+ configuration files (.yarn, .yarnrc.yml) that are created when using yarn

  3. Manual verification: Tested the exact command from the bug report:

    npx @react-native-community/cli@latest init RN0821Test3 --skip-install --pm yarn

    This now completes successfully without errors.

  4. Regression testing: Verified that:

    • --pm yarn without --skip-install still works
    • --pm npm with --skip-install still works
    • --pm bun with --skip-install still works
    • Custom templates with --install-pods false no longer fail with react-native resolution errors

Changes made:

  • packages/cli/src/commands/init/template.ts: Added await to yarn config executeCommand calls to ensure they complete before template installation
  • packages/cli/src/commands/init/init.ts: Moved require.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 files

Checklist

  • Documentation is up to date.
  • Follows commit message convention described in CONTRIBUTING.md.
  • For functional changes, my test plan has linked these CLI changes into a local react-native checkout (instructions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specifying --pm yarn and --skip-install together causes init failure

1 participant