升级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 existReferenceError: 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
相关产品推荐
相关产品推荐

