React-Native:在项目或这些目录中找不到 React

Sim*_*sch 9 xcode objective-c ios reactjs react-native

我们已经使用 react (16.9.0) 将我们的 react native 项目升级到了最新的 react native 版本 (v0.61.2),它在 android 上运行良好。当我们尝试在 ios think 上运行它时,我们得到以下消息:

warning: the transform cache was reset. Loading dependency graph, done. error: bundling failed: Error: Unable to resolve module `React` from `ios/Pods/React/Libraries/react-native/react-native.js`: React could not be found within the project or in these directories:   node_modules

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules: rm -rf node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
Run Code Online (Sandbox Code Playgroud)

我们遵循了升级指南,将所有依赖项更新到了最新版本并更新了 pod。我实际上不知道从哪里或如何开始调试它,因为这似乎来自 Pods 文件夹。

这是我们 Pods 文件夹的内容:

ls ios/Pods/
Adjust              GoogleDataTransport
Crashlytics         GoogleDataTransportCCTSupport
DoubleConversion        GoogleUtilities
Fabric              Headers
Firebase            Local Podspecs
FirebaseABTesting       Manifest.lock
FirebaseAnalytics       Pods.xcodeproj
FirebaseAnalyticsInterop    Protobuf
FirebaseCore            Pushwoosh
FirebaseCoreDiagnostics     PushwooshInboxUI
FirebaseCoreDiagnosticsInterop  React
FirebaseDynamicLinks        Target Support Files
FirebaseInstanceID      boost-for-react-native
FirebaseRemoteConfig        glog
Folly               nanopb
GoogleAppMeasurement
Run Code Online (Sandbox Code Playgroud)

在我们的 node_modules 文件夹中,我们有(还有更多其他包):

...
react
depd                        react-deep-force-update
des.js                      react-devtools-core
destroy                     react-is
detect-libc                 react-lifecycles-compat
detect-newline              react-native
...
Run Code Online (Sandbox Code Playgroud)

当然,我已经尝试了所有步骤,例如清除缓存、重置缓存、清除派生数据、清理和构建……我不知道从哪里开始寻找。

fhd*_*sni 7

我通过更换来修复它

import Foobar from "screens/foobar";
Run Code Online (Sandbox Code Playgroud)

import Foobar from "./screens/foobar";
Run Code Online (Sandbox Code Playgroud)

注意./路径的开头


Len*_*rod 0

上周,我也遇到了这个问题,它是由react路径改变引起的。

打开你的ios文件夹Podfile,编辑react路径。它已经转移到react-native

 pod 'React', :path => '../node_modules/react-native/'
 pod 'React-Core', :path => '../node_modules/react-native/'
Run Code Online (Sandbox Code Playgroud)

然后 cd ios 文件夹并在终端中运行 pod install

除上述之外,如果您还遇到其他升级问题,可以到本站对比相关文件