简单来说,当我使用yarn - Berry或任何较新版本3.x或4.x时,我无法为react-native项目安装pod。有人做过这个工作吗?谢谢!
可以按照以下步骤重新引入:
1 - 纱线套装版浆果
2 - npx 反应本机 init abc
安装 pod 文件时会失败。对于现有项目也是如此。我正在使用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
这是我的 pod 文件的样子:
# 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
还有package.json文件:
{
"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"
}
}
谢谢!
简单来说,当我使用yarn - Berry或任何较新版本3.x或4.x时,我无法为react-native项目安装pod。有人做过这个工作吗?谢谢!
将 .yarnrc.yml 文件添加到项目的根目录,内容如下:
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.1.1.cjs
还将
"packageManager": "[email protected]"
添加到您的 package.json
然后删除
node_modules
和 yarn.lock
运行
yarn set version 4.1.1
,然后运行 yarn install
,然后尝试安装 pods