iosreact-nativecocoapodsyarn-v3yarn-berry

Failure of pod install for the React-native project using Yarn Berry


Simply, I can't install the pod for the react-native project when I use the yarn - Berry or any newer version 3.x or 4.x. Is there anyone who made this work? Thanks!

This can be re-introduced by following these steps:

1 - yarn set version berry

2 - npx react-native init abc

You will get failure for installing the pod files. The same for the existing projects as well. I am using react-native 0.74.0, 0.74.1

 #  from /Users/administrator/Desktop/abc/ios/Podfile:2
 #  -------------------------------------------
 #  # Resolve react_native_pods.rb with node to allow for hoisting
 >  require Pod::Executable.execute_command('node', ['-p',
 #    'require.resolve(
 #  -------------------------------------------
Couldn't install Pods. Updating the Pods project and trying again...
Command `pod install` failed.
└─ Cause: Invalid `Podfile` file: [!] /opt/homebrew/bin/node -p require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  ) /Users/administrator/Desktop/abc/ios

node:internal/modules/cjs/loader:1205
  throw err;
  ^

Error: Cannot find module 'react-native/scripts/react_native_pods.rb'
Require stack:
- /Users/administrator/Desktop/abc/ios/[eval]
    at Module._resolveFilename (node:internal/modules/cjs/loader:1202:15)
    at Function.resolve (node:internal/modules/helpers:199:19)
    at [eval]:1:9
    at runScriptInThisContext (node:internal/vm:209:10)
    at node:internal/process/execution:118:14
    at [eval]-wrapper:6:24
    at runScript (node:internal/process/execution:101:62)
    at evalScript (node:internal/process/execution:136:3)
    at node:internal/main/eval_string:51:3 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/administrator/Desktop/abc/ios/[eval]' ]
}

Node.js v22.0.0

Here is how my pod file looks like:

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'abc' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'abcTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
      # :ccache_enabled => true
    )
  end
end

And package.json file:

{
  "name": "abc",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.74.1"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.74.83",
    "@react-native/eslint-config": "0.74.83",
    "@react-native/metro-config": "0.74.83",
    "@react-native/typescript-config": "0.74.83",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
}

Thanks!

Simply, I can't install the pod for the react-native project when I use the yarn - Berry or any newer version 3.x or 4.x. Is there anyone who made this work? Thanks!


Solution

  • Add .yarnrc.yml file to root of your project with content:

    nodeLinker: node-modules
    
    yarnPath: .yarn/releases/yarn-4.1.1.cjs
    

    Also add "packageManager": "yarn@4.1.1" to your package.json

    Then delete node_modules and yarn.lock

    Run yarn set version 4.1.1, then yarn install and after this try to install pods