cli: Error: Cannot find module 'react-native/scripts/react_native_pods.rb'

Environment

System:
  OS: macOS 14.1.1
  CPU: (12) arm64 Apple M2 Max
  Memory: 1.21 GB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.17.1
    path: /usr/local/bin/node
  Yarn:
    version: 3.6.2
    path: /usr/local/bin/yarn
  npm:
    version: 9.6.7
    path: /usr/local/bin/npm
  Watchman:
    version: 2023.11.20.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/user/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.11005911
  Xcode:
    version: 15.0.1/15A507
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.21
    path: /usr/bin/javac
  Ruby:
    version: 3.2.2
    path: /Users/user/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.7
    wanted: 0.72.7
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: true

Description

when running npx react-native@latest init AwesomeProject,

✖ Installing CocoaPods dependencies (this may take a few minutes)
error 
[!] Invalid `Podfile` file: [!] /usr/local/bin/node -p require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  ) /Users/user/Documents/sources/AwesomeProject/ios

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

Error: Cannot find module 'react-native/scripts/react_native_pods.rb'
Require stack:
- /Users/user/Documents/sources/AwesomeProject/ios/[eval]
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Function.resolve (node:internal/modules/cjs/helpers:127:19)
    at [eval]:1:9
    at Script.runInThisContext (node:vm:123:12)
    at Object.runInThisContext (node:vm:299:38)
    at node:internal/process/execution:79:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:78:60)
    at node:internal/main/eval_string:28:3 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/user/Documents/sources/AwesomeProject/ios/[eval]' ]
}

Node.js v18.17.1
.

 #  from /Users/user/Documents/sources/AwesomeProject/ios/Podfile:2
 #  -------------------------------------------
 #  # Resolve react_native_pods.rb with node to allow for hoisting
 >  require Pod::Executable.execute_command('node', ['-p',
 #    'require.resolve(
 #  -------------------------------------------
✖ Installing CocoaPods dependencies (this may take a few minutes)
error Looks like your iOS environment is not properly set. Please go to https://reactnative.dev/docs/environment-setup?os=macos&platform=android and follow the React Native CLI QuickStart guide for macOS and iOS.
info Run CLI with --verbose flag for more details.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 16

Most upvoted comments

This problem occurs when we install bundle and then go for pod without installing node_modules… so first install node_modules so that when native files fetch react native files it must be available in node_modules…

DONOT try to run on debugger. Stop the debugger try npm i -f and then cd ios then pod install.

@orange4glace You’re using Yarn v3 with PnP if you’re inside monorepo, please use nodeLinker: node-modules inside .yarnrc.yml config file. Or if you’re not in monorepo please downgrade Yarn to v1, or if you don’t want - you can use latest RC which already contains a fix for this:

npx react-native init RN073RC6 --version 0.73.0-rc.6

I was getting this same error. I was able to resolve with the following:

From the project root npm install nvm use 18 cd ios bundle exec pod install

Hopefully this helps someone else.

hey @sujitmohanty, you should do it inside project’s directory. or if you want to keep Yarn v3, you just need to provide .yarnrc.yml with nodeLinker: node-modules.

hey @exequiel-criss, please make sure that you’re node_modules are installed correctly and also that you’re using nodeLinker: node-modules with higher Yarn versions.

@raushanxstan awesome! thanks for guide me

@szymonrybczak

I’m getting a similar error, please take a look into it. If it’s irrelevant, please let me know to create a new issue.

I’m using NPM instead of Yarn in my project. should we necessarily use Yarn to make pod install work? I should mention that I don’t have macOS, so I installed Cocoapods v1.15.2 (the latest version as I’m writing this comment) on my Windows 10 and I’m trying to install dependencies and make the pod.lock file for the project.

I already have node_modules installed in my project and this is my Podfile’s content from RN v0.74.3:

# 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 'AppMobile' do
  config = use_native_modules!

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

  target 'AppMobileTests' 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

when executing pod install in the ios directory it gives me this error:

pod install --verbose
  $ C:/Program Files/nodejs/node.exe -p require.resolve(     "react-native/scripts/react_native_pods.rb",     {paths: [process.argv[1]]},   ) C:/Users/saeed/workspace/AppMobile/ios
  C:\Users\saeed\workspace\AppMobile\node_modules\react-native\scripts\react_native_pods.rb
  $ C:/Program Files/nodejs/node.exe -p require.resolve(     "@react-native-community/cli-platform-ios/native_modules.rb",     {paths: [process.argv[1]]},   )
  C:/Users/saeed/workspace/AppMobile/node_modules/react-native/scripts
  C:\Users\saeed\workspace\AppMobile\node_modules\@react-native-community\cli-platform-ios\native_modules.rb

[!] Invalid `Podfile` file: No such file or directory - command -v node.

 #  from C:/Users/saeed/workspace/AppMobile/ios/Podfile:9
 #  -------------------------------------------
 #    end
 >  end
 #  # Resolve react_native_pods.rb with node to allow for hoisting
 #  -------------------------------------------

C:/Users/saeed/.local/share/gem/ruby/3.3.0/gems/cocoapods-core-1.15.2/lib/cocoapods-core/podfile.rb:335:in `rescue in block in from_ruby'
C:/Users/saeed/.local/share/gem/ruby/3.3.0/gems/cocoapods-core-1.15.2/lib/cocoapods-core/podfile.rb:329:in `block in from_ruby'
C:/Users/saeed/.local/share/gem/ruby/3.3.0/gems/cocoapods-core-1.15.2/lib/cocoapods-core/podfile.rb:50:in `instance_eval'
C:/Users/saeed/.local/share/gem/ruby/3.3.0/gems/cocoapods-core-1.15.2/lib/cocoapods-core/podfile.rb:50:in `initialize'
C:/Users/saeed/.local/share/gem/ruby/3.3.0/gems/cocoapods-core-1.15.2/lib/cocoapods-core/podfile.rb:327:in `new'
C:/Users/saeed/.local/share/gem/ruby/3.3.0/gems/cocoapods-core-1.15.2/lib/cocoapods-core/podfile.rb:327:in `from_ruby'
C:/Users/saeed/.local/share/gem/ruby/3.3.0/gems/cocoapods-core-1.15.2/lib/cocoapods-core/podfile.rb:293:in `from_file'
C:/Users/saeed/.local/share/gem/ruby/3.3.0/gems/cocoapods-1.15.2/lib/cocoapods/config.rb:206:in `podfile'
C:/Users/saeed/.local/share/gem/ruby/3.3.0/gems/cocoapods-1.15.2/lib/cocoapods/command.rb:160:in `verify_podfile_exists!'
C:/Users/saeed/.local/share/gem/ruby/3.3.0/gems/cocoapods-1.15.2/lib/cocoapods/command/install.rb:46:in `run'
C:/Users/saeed/.local/share/gem/ruby/3.3.0/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
C:/Users/saeed/.local/share/gem/ruby/3.3.0/gems/cocoapods-1.15.2/lib/cocoapods/command.rb:52:in `run'
C:/Users/saeed/.local/share/gem/ruby/3.3.0/gems/cocoapods-1.15.2/bin/pod:55:in `<top (required)>'
C:/Users/saeed/AppData/Local/Microsoft/WindowsApps/pod:32:in `load'
C:/Users/saeed/AppData/Local/Microsoft/WindowsApps/pod:32:in `<main>'

if you want to keep Yarn v3, you just need to provide .yarnrc.yml with nodeLinker: node-modules.

Ahh I see. Thank you so much for responding!

hey @exequiel-criss, please make sure that you’re node_modules are installed correctly and also that you’re using nodeLinker: node-modules with higher Yarn versions.

Thank you so much! I was able to solve it, I had to create a file in the root of the project with the name .yarnrc and inside the file --install.nodeLinker=node-modules Then I deleted the node_modules folder, I did a pod install and a yarn install and it was solved.