"use_native_modules!" 的 react-native ios Podfile 问题
react-native ios Podfile issue with "use_native_modules!"
在我的 ios/ 目录中的 react-native 项目 (react-native@0.60) 我 运行 pod install
并得到这个错误:
[!] Invalid `Podfile` file: no implicit conversion of nil into String.
# from /Users/coryrobinson/projects/hhs2/ios/Podfile:37
# -------------------------------------------
#
> use_native_modules!
# end
# -------------------------------------------
我没有在这个 Podfile 中添加或更改任何内容 - 它都是 react-native 生成的。 (我在 iOS 开发方面没有经验,所以这可能是一个简单的修复,我只是不知道要寻找什么:-|)感谢您的帮助!
这是我的 Podfile
platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
target 'hhs2' do
# Pods for hhs2
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/React'
pod 'React-DevSupport', :path => '../node_modules/react-native/React'
pod 'React-fishhook', :path => '../node_modules/react-native/Libraries/fishhook'
pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
pod 'React-RCTWebSocket', :path => '../node_modules/react-native/Libraries/WebSocket'
pod 'RNFS', :path => '../node_modules/react-native-fs'
pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
target 'hhs2Tests' do
inherit! :search_paths
# Pods for testing
end
use_native_modules!
end
target 'hhs2-tvOS' do
# Pods for hhs2-tvOS
target 'hhs2-tvOSTests' do
inherit! :search_paths
# Pods for testing
end
end
删除几个 react-native npm 包后(即:react-native-bluetooth-serial、react-native-sound 等...)pod install
有效。
pod 安装错误似乎与不支持 cocoa pods 的旧 react-native 软件包有关?我不确定细节,但是从 node_modules 和 package.json 中删除这些包解决了我的问题。
删除行 use_native_modules!
也可以。也许这已被弃用或语法已更改?很想听听其他人的意见。
更新:似乎是 react-native 0.60.0 的问题。在发布修复此错误之前,可以显式安装 0.59.10,您只需要根据需要添加 CocoaPods。
react-native init APP_NAME --version react-native@0.59.10
我刚刚删除了整个 node_modules 和 RN 缓存文件夹并进行了干净的重新安装,这解决了 "use_native_modules" 到目前为止的问题....但在那之后我不得不麻烦很多其他没有准备好 RN0.60 的库 ;)
正确答案如下:
1 - 您的 POD 文件应在顶部包含此行
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
2 - 确保您的 package.json
和 node_module
文件夹安装了此模块
cli-platform-ios/native_modules
3 - 如果你在 运行 yarn install
之后没有找到 - 意味着你的机器中有旧缓存 node_modules 并且你需要在重新安装包之前清理它.
4 - 清理缓存 yarn cache clean
5 - 确保你有这个文件 react-native.config.js
并且它的配置是有效的 - 并且它没有不存在的 NPM 包 - 这一步是最后也是主要的原因错误
我的例子 react-native.config.js
module.exports = {
project: {
ios: {},
android: {},
},
assets: ['./assets/fonts/'],
dependencies: {}, // make sure this dependencies are all valid installed packages or empty if you don't need it
};
6 - 安装节点包 yarn install
,您的 pods 现在应该可以工作了! pod install --repo-update
编码愉快!
如果您正在使用
pod install --project-directory=ios
您可能需要通过替换
来调整 Podfile
use_native_modules!
至
use_native_modules!(".")
也许这个行为以后会得到改善,我开了一个关于它的问题https://github.com/react-native-community/cli/issues/657
原因之一可能是 Ruby 版本过时。使用以下命令升级它。
rvm install 2.6.1
rvm use 2.6.1 --default
或者您可以按照下面的文章进行操作,其中详细说明了升级 ruby 和相关宝石。
https://help.learn.co/en/articles/2789231-how-to-upgrade-from-ruby-2-3-to-2-6
这是因为您设备上的 yarn 版本过时,
如果你在 macOS 上,你可以 upgrade/install 遵循这个 link 的纱线:
here it is
注意删除node-module
和yarn.lock
文件,重新安装所有包,导航至ios 文件夹和 运行 pod install
.
对我来说,我删除了 node_modules
并使用 npm install
重新安装。之后,我导航到 /ios
文件夹并且 运行 pod install
它起作用了。
问题是:
use_native_modules!
早期版本的 CocoaPods 不支持。例如,我们的安装是从 CocaoPods website 下载的应用程序。那个版本是 1.5.2
.
运行:
pod --version
查看哪个版本。如果需要,卸载然后重新安装,但在终端中按 运行:
sudo gem install cocoapods
至少截至 2019 年 10 月下旬,当前 gem 可用版本为 1.8.4
。成功安装后,重新尝试 pod install
,希望一切顺利。
我在尝试 react-native run-ios
Expo 应用程序后遇到此错误。我得到的错误表明 Pods 有问题,所以我 运行 cd ios && pod install
,这就是我得到与 OP 类似的错误的原因。
在那种情况下,您显然需要 expo start
而不是 react-native run-ios
。
验证您的 package.json,
中是否有 @react-native-community/cli-platform-ios
如果你不运行:
npm install @react-native-community/cli-platform-ios
然后
cd ios && pod install
转到此存储库:ProjectName -> ios -> Podfile
- 在
Podfile
中删除use_native_modules
!
- 再次执行pod install
- 享受你的新连播
这是今天突然发生的事情,问题出在我的目录结构中 space。例如:
/path/to/Directory\ Name/RNProject 抛出 !native_modules 错误
/path/to/DirectoryName/RNProject 正常工作
Pods 正在寻找 "Directory. "
将@react-native-community/cli-platform-ios 从 3.1.0 降级到 3.0.0 并且它有效。
已添加
"@react-native-community/cli-platform-ios": "3.0.0"
至package.json。
运行 npm install 然后 pod install 让它再次工作。
有没有人针对这个问题有一个不以摆脱 use_native_modules 为中心的始终如一的可重新创建的解决方案?我调查过:
- 正在更改 Ruby 版本
- 正在更改 CocoaPods 版本
- 使 NPM 和 Cocoapods 缓存失效
我无法解决这个问题。它似乎是一些 npm 依赖项,但我团队中的其他人没有看到它。
好的,我猜对于大多数人来说,接受的答案将解决他们的问题。对我来说,修复太奇怪了,我不得不在这里添加它。
出于某种原因,我最终在 android 本机设置中创建了一个无效的 AndroidManifest.xml
文件。
我查看了完整的错误输出,错误的第一行引用了行号和列号。那时在我的 xml 文件中我破坏了 xml 格式。
2 天搜索找到 GitHub 问题,其中描述了 look。
可能与权利问题有关
在 package.json
中添加“@react-native-community/cli-platform-ios”:“3.0.0”
和
sudo chown -R 用户。
对我有用
不要使用纱线安装。这就是对我有用的...
- 转到主文件夹
- 删除节点文件夹
- 运行
sudo npm install
或者 npm install
cd ios
pod install
在 AppCenter 上构建应用程序时遇到同样的问题,本地运行完美
是否有可能跟踪此错误?因为我已经看到我看到它的原因有很多。
根据 blog post from one of JavaScript Guru's.
得到它的工作
轻松:
- 运行
sudo xcode-select --switch /Applications/Xcode.app
在您的 React Native
项目的 root
中。
- 在
ios
文件夹中 运行 pod install
。
编辑:
没有破解任何:
@react-native-community/cli-platform-ios
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
需要。
在我的 ios/ 目录中的 react-native 项目 (react-native@0.60) 我 运行 pod install
并得到这个错误:
[!] Invalid `Podfile` file: no implicit conversion of nil into String.
# from /Users/coryrobinson/projects/hhs2/ios/Podfile:37
# -------------------------------------------
#
> use_native_modules!
# end
# -------------------------------------------
我没有在这个 Podfile 中添加或更改任何内容 - 它都是 react-native 生成的。 (我在 iOS 开发方面没有经验,所以这可能是一个简单的修复,我只是不知道要寻找什么:-|)感谢您的帮助!
这是我的 Podfile
platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
target 'hhs2' do
# Pods for hhs2
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/React'
pod 'React-DevSupport', :path => '../node_modules/react-native/React'
pod 'React-fishhook', :path => '../node_modules/react-native/Libraries/fishhook'
pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
pod 'React-RCTWebSocket', :path => '../node_modules/react-native/Libraries/WebSocket'
pod 'RNFS', :path => '../node_modules/react-native-fs'
pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
target 'hhs2Tests' do
inherit! :search_paths
# Pods for testing
end
use_native_modules!
end
target 'hhs2-tvOS' do
# Pods for hhs2-tvOS
target 'hhs2-tvOSTests' do
inherit! :search_paths
# Pods for testing
end
end
删除几个 react-native npm 包后(即:react-native-bluetooth-serial、react-native-sound 等...)pod install
有效。
pod 安装错误似乎与不支持 cocoa pods 的旧 react-native 软件包有关?我不确定细节,但是从 node_modules 和 package.json 中删除这些包解决了我的问题。
删除行 use_native_modules!
也可以。也许这已被弃用或语法已更改?很想听听其他人的意见。
更新:似乎是 react-native 0.60.0 的问题。在发布修复此错误之前,可以显式安装 0.59.10,您只需要根据需要添加 CocoaPods。
react-native init APP_NAME --version react-native@0.59.10
我刚刚删除了整个 node_modules 和 RN 缓存文件夹并进行了干净的重新安装,这解决了 "use_native_modules" 到目前为止的问题....但在那之后我不得不麻烦很多其他没有准备好 RN0.60 的库 ;)
正确答案如下:
1 - 您的 POD 文件应在顶部包含此行
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
2 - 确保您的 package.json
和 node_module
文件夹安装了此模块
cli-platform-ios/native_modules
3 - 如果你在 运行 yarn install
之后没有找到 - 意味着你的机器中有旧缓存 node_modules 并且你需要在重新安装包之前清理它.
4 - 清理缓存 yarn cache clean
5 - 确保你有这个文件 react-native.config.js
并且它的配置是有效的 - 并且它没有不存在的 NPM 包 - 这一步是最后也是主要的原因错误
我的例子 react-native.config.js
module.exports = {
project: {
ios: {},
android: {},
},
assets: ['./assets/fonts/'],
dependencies: {}, // make sure this dependencies are all valid installed packages or empty if you don't need it
};
6 - 安装节点包 yarn install
,您的 pods 现在应该可以工作了! pod install --repo-update
编码愉快!
如果您正在使用
pod install --project-directory=ios
您可能需要通过替换
来调整 Podfileuse_native_modules!
至
use_native_modules!(".")
也许这个行为以后会得到改善,我开了一个关于它的问题https://github.com/react-native-community/cli/issues/657
原因之一可能是 Ruby 版本过时。使用以下命令升级它。
rvm install 2.6.1
rvm use 2.6.1 --default
或者您可以按照下面的文章进行操作,其中详细说明了升级 ruby 和相关宝石。
https://help.learn.co/en/articles/2789231-how-to-upgrade-from-ruby-2-3-to-2-6
这是因为您设备上的 yarn 版本过时, 如果你在 macOS 上,你可以 upgrade/install 遵循这个 link 的纱线: here it is
注意删除node-module
和yarn.lock
文件,重新安装所有包,导航至ios 文件夹和 运行 pod install
.
对我来说,我删除了 node_modules
并使用 npm install
重新安装。之后,我导航到 /ios
文件夹并且 运行 pod install
它起作用了。
问题是:
use_native_modules!
早期版本的 CocoaPods 不支持。例如,我们的安装是从 CocaoPods website 下载的应用程序。那个版本是 1.5.2
.
运行:
pod --version
查看哪个版本。如果需要,卸载然后重新安装,但在终端中按 运行:
sudo gem install cocoapods
至少截至 2019 年 10 月下旬,当前 gem 可用版本为 1.8.4
。成功安装后,重新尝试 pod install
,希望一切顺利。
我在尝试 react-native run-ios
Expo 应用程序后遇到此错误。我得到的错误表明 Pods 有问题,所以我 运行 cd ios && pod install
,这就是我得到与 OP 类似的错误的原因。
在那种情况下,您显然需要 expo start
而不是 react-native run-ios
。
验证您的 package.json,
中是否有@react-native-community/cli-platform-ios
如果你不运行:
npm install @react-native-community/cli-platform-ios
然后
cd ios && pod install
转到此存储库:ProjectName -> ios -> Podfile
- 在
Podfile
中删除use_native_modules
! - 再次执行pod install
- 享受你的新连播
这是今天突然发生的事情,问题出在我的目录结构中 space。例如:
/path/to/Directory\ Name/RNProject 抛出 !native_modules 错误 /path/to/DirectoryName/RNProject 正常工作
Pods 正在寻找 "Directory. "
将@react-native-community/cli-platform-ios 从 3.1.0 降级到 3.0.0 并且它有效。
已添加
"@react-native-community/cli-platform-ios": "3.0.0"
至package.json。
运行 npm install 然后 pod install 让它再次工作。
有没有人针对这个问题有一个不以摆脱 use_native_modules 为中心的始终如一的可重新创建的解决方案?我调查过:
- 正在更改 Ruby 版本
- 正在更改 CocoaPods 版本
- 使 NPM 和 Cocoapods 缓存失效
我无法解决这个问题。它似乎是一些 npm 依赖项,但我团队中的其他人没有看到它。
好的,我猜对于大多数人来说,接受的答案将解决他们的问题。对我来说,修复太奇怪了,我不得不在这里添加它。
出于某种原因,我最终在 android 本机设置中创建了一个无效的 AndroidManifest.xml
文件。
我查看了完整的错误输出,错误的第一行引用了行号和列号。那时在我的 xml 文件中我破坏了 xml 格式。
2 天搜索找到 GitHub 问题,其中描述了 look。
可能与权利问题有关
在 package.json
中添加“@react-native-community/cli-platform-ios”:“3.0.0”和
sudo chown -R 用户。
对我有用
不要使用纱线安装。这就是对我有用的...
- 转到主文件夹
- 删除节点文件夹
- 运行
sudo npm install
或者npm install
cd ios
pod install
在 AppCenter 上构建应用程序时遇到同样的问题,本地运行完美
是否有可能跟踪此错误?因为我已经看到我看到它的原因有很多。
根据 blog post from one of JavaScript Guru's.
得到它的工作轻松:
- 运行
sudo xcode-select --switch /Applications/Xcode.app
在您的React Native
项目的root
中。 - 在
ios
文件夹中 运行pod install
。
编辑:
没有破解任何:
@react-native-community/cli-platform-ios
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
需要。