You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Expo@52.0.7后expo-linear-gradient报'React不存在'错误求助

Expo 52.0.7 升级后 expo-linear-gradient 报错问题

将Expo从51.0.17版本升级至52.0.7版本后,expo-linear-gradient库开始抛出两类错误:

  • Render Error: Property 'React' doesn't exist
  • ReferenceError: Property 'React' doesn't exist

组件使用方式

我在项目中使用LinearGradient的代码如下:

<LinearGradient
    colors={["rgba(0,0,0,0.0)", `rgba(0,0,0,${gradientBottomOpacity})`]}
    style={$gradient}
/>

升级前该代码运行完全正常。

问题排查方向

我推测问题与expo-linear-gradient包的React导入方式有关,查看该包的NativeLinearGradient.android.tsx文件后,发现其React导入语句为import * as React from 'react'。

已尝试的无效方案

我尝试在babel.config.js的presets中添加{ useTransformReactJSXExperimental: true },完整配置代码如下:

const plugins = [
  [
    "@babel/plugin-proposal-decorators",
    {
      legacy: true,
    },
  ],
  ["@babel/plugin-proposal-optional-catch-binding"],
  [
    "@babel/plugin-transform-private-methods",
    {
      loose: true, // Ensure 'loose' mode is set otherwise it will throw an error on starting the server
    },
  ],
  [
    "@babel/plugin-transform-private-property-in-object",
    {
      loose: true, // Ensure 'loose' mode is set otherwise it will throw an error on starting the server
    },
  ],
  "react-native-reanimated/plugin", // NOTE: this must be last in the plugins
]

const vanillaConfig = {
  presets: ["module:metro-react-native-babel-preset"],
  env: {
    production: {},
  },
  plugins,
}

const expoConfig = {
  presets: [["babel-preset-expo", {  useTransformReactJSXExperimental: true  }]],
  env: {
    production: {},
  },
  plugins,
}

let isExpo = false
try {
  const Constants = require("expo-constants")
  // True if the app is running in an `expo build` app or if it's running in Expo Go.
  isExpo =
    Constants.executionEnvironment === "standalone" ||
    Constants.executionEnvironment === "storeClient"
} catch {}

const babelConfig = isExpo ? expoConfig : vanillaConfig

module.exports = babelConfig

但该配置并未解决问题,寻求可行的解决方案。


内容的提问来源于stack exchange,提问作者stehvanin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 04:27:38