【问题标题】:Expo "Error: Your JavaScript code tried to access a native module that doesn't exist", how to find the modules that are not compatible with Expo?Expo“错误:您的 JavaScript 代码试图访问不存在的本机模块”,如何找到与 Expo 不兼容的模块?
【发布时间】:2023-02-01 03:04:35
【问题描述】:

我正在研究一个使用 React Native CLI roginally 创建的 React Native 项目。其他团队成员在我加入之前就已经开始工作了,所以我现在基本上是在为这个项目做贡献。 我需要在物理设备上预览应用程序,并且由于我使用的是 Windows 且只有 iOS 设备,所以我安装了 Expo。我可以运行 npx expo start 并扫描二维码,这会启动 Expo Go 应用程序,但显示 4 个错误(和 1 个警告)。

其中一个错误说我的"JavaScript code tried to access a native module that doesn't exist" 但没有准确指出有问题的模块,这使得很难找出问题所在。

我试着用谷歌搜索这个错误,但似乎没有什么关于它的信息。我找到了这个question,但它并不能真正帮助查明导致问题的确切模块。 我还可以在阅读 Expo doc 时发现我无法添加自定义本机代码。 TypeScript 代码是否可能包含 Expo 不支持的模块?

另一个错误似乎来自不匹配类型(“undefined is not an object”),但我还是无法理解它。

这次我最终使用 Expo CLI 从头开始​​创建一个项目,只复制源文件,不包括 androidios 文件夹以确保它们是从头开始重建的,运行 yarn install 重新创建包.json,但错误仍然存​​在。所以错误肯定是在 TypeScript 代码中,但我没有足够的知识来找出它。

错误,按照它们在日志控制台中出现的顺序排列:

1)

TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[7], "../features/auth/screens").OnboardingScreen')

This error is located at:
    in AppStackNavigator (at App.tsx:25)
    in AuthContextProvider (at App.tsx:24)
    in EnsureSingleNavigator (at BaseNavigationContainer.tsx:430)
    in BaseNavigationContainer (at NavigationContainer.tsx:132)
    in ThemeProvider (at NavigationContainer.tsx:131)
    in NavigationContainerInner (at App.tsx:23)
    in RCTView (at View.js:32)
    in View (at GestureHandlerRootView.tsx:17)
    in GestureHandlerRootView (at App.tsx:22)
    in App (created by ExpoRoot)
    in ExpoRoot (at renderApplication.js:50)
    in RCTView (at View.js:32)
    in View (at AppContainer.js:92)
    in DevAppContainer (at AppContainer.js:107)
    in RCTView (at View.js:32)
    in View (at AppContainer.js:119)
    in AppContainer (at renderApplication.js:43)
    in main(RootComponent) (at renderApplication.js:60)
Invariant Violation: Your JavaScript code tried to access a native module that doesn't exist.

If you're trying to use a module that is not supported in Expo Go, you need to create a development build of your app. See https://docs.expo.dev/development/introduction/ for more info
Error: Your JavaScript code tried to access a native module that doesn't exist.

If you're trying to use a module that is not supported in Expo Go, you need to create a development build of your app. See https://docs.expo.dev/development/introduction/ for more info.
TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[7], "../features/auth/screens").OnboardingScreen')

This error is located at:
    in AppStackNavigator (at App.tsx:25)
    in AuthContextProvider (at App.tsx:24)
    in EnsureSingleNavigator (at BaseNavigationContainer.tsx:430)
    in BaseNavigationContainer (at NavigationContainer.tsx:132)
    in ThemeProvider (at NavigationContainer.tsx:131)
    in NavigationContainerInner (at App.tsx:23)
    in RCTView (at View.js:32)
    in View (at GestureHandlerRootView.tsx:17)
    in GestureHandlerRootView (at App.tsx:22)
    in App (created by ExpoRoot)
    in ExpoRoot (at renderApplication.js:50)
    in RCTView (at View.js:32)
    in View (at AppContainer.js:92)
    in DevAppContainer (at AppContainer.js:107)
    in RCTView (at View.js:32)
    in View (at AppContainer.js:119)
    in AppContainer (at renderApplication.js:43)
    in main(RootComponent) (at renderApplication.js:60)

【问题讨论】:

    标签: typescript react-native expo expo-go


    【解决方案1】:

    朋友,下午好!

    打开名为 = screens 的文件,然后查看它是否具有函数 = OnboardingScreen,查看它调用了哪些 lib 和/或其他函数。

    拥抱

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-23
      • 2023-01-14
      • 1970-01-01
      • 2018-09-24
      • 2023-01-17
      • 2019-06-20
      • 2019-10-12
      • 2020-04-01
      相关资源
      最近更新 更多