【问题标题】:React Native/Expo + Next.js app crashes in Expo app (Can't find variable: React, in withExpoRoot.js)React Native/Expo + Next.js 应用程序在 Expo 应用程序中崩溃(找不到变量:React,在 withExpoRoot.js 中)
【发布时间】:2021-03-12 05:17:36
【问题描述】:

我有一个 React Native/Expo + Next.js 应用程序(使用 npx create-next-app -e with-expo 构建)

完整代码:https://github.com/tomsoderlund/reactnative-nextjs-template

它作为网络应用程序运行良好(在 Next.js 和 Expo Web 中),但在 iPhone 上的 Expo 应用程序上运行时崩溃:

ReferenceError: Can't find variable: React

This error is located at:
    in App (at withExpoRoot.js:26)
    in ExpoRoot (at renderApplication.js:40)
    in RCTView (at AppContainer.js:101)
    in DevAppContainer (at AppContainer.js:115)
    in RCTView (at AppContainer.js:119)
    in AppContainer (at renderApplication.js:39)

我怎样才能让它运行?

【问题讨论】:

  • 您是否尝试在您的index.js 页面顶部添加import React from 'react'
  • @juliomalves 天哪,就是这么简单!谢谢!

标签: react-native expo next.js


【解决方案1】:

您需要在 index.js 页面的顶部导入 React,以便在 Expo 中运行您的应用时获取它。

import React from 'react'

【讨论】:

    猜你喜欢
    • 2023-02-02
    • 1970-01-01
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 2022-12-29
    • 2022-07-21
    相关资源
    最近更新 更多