我已经使用推荐的模板创建了一个新的 React Native 项目,但是当我尝试为这个新项目安装 pod 时,出现以下错误:
[!] Invalid `Podfile` file: cannot load such file -- /Users/..../AwesomeProject/node_modules/react-native/scripts/react_native_pods.rb
我的 Podfile:
# 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 'AwesomeProject' 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 'AwesomeProjectTests' 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
节点-v:21.6.1 Pod 版本:1.15.2
我检查了react_native_pods.rb是否存在于node_modules中...react-native/scripts/react_native_pods.rb
尝试使用yarn和默认npm,两者都会给出上述错误(尝试清理缓存)。 npm 审计修复也没有帮助。
尝试通过brew reinstall cocoapods重新安装pod,但在React Native项目的ios文件夹中使用pod install时遇到相同的错误。
通过bundle exec pod install 安装 pod 也没有帮助。
最奇怪的是,两周前我能够为我的所有项目安装 Pod。但是当我现在这样做时,在不更改操作系统中的任何内容的情况下,即使在 npx react-native@latest init AwesomeProject 新创建的项目中,我也无法安装 pod。
找到了解决方案:
问题出在我的 IDE(VS Code)中: 我不小心启用了 Javascript 自动附加过滤器到 Smart(默认禁用),这导致反应原生项目中的每个 pod 安装都失败。