最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - expo-linear-gradient throws "Property 'React' doesn't exist" error - Stack O

programmeradmin1浏览0评论

After I updated from [email protected] to [email protected] the expo-linear-gradient library started throwing Render Error: Property 'React' doesn't exist and ReferenceError: Property 'React' doesn't exist.

This is how I use LinearGradient in my components:

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

Everything was working well before the update.

I believe it have something to do with how the expo-linear-gradient imports React. In the package's NativeLinearGradient.android.tsx component it import the React as import * as React from 'react'.

I tried adding { useTransformReactJSXExperimental: true } in babel.config.js in presets

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

发布评论

评论列表(0)

  1. 暂无评论