首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >升级React应用程序使用JSX转换-破坏应用程序(Propery 'React‘不存在)

升级React应用程序使用JSX转换-破坏应用程序(Propery 'React‘不存在)
EN

Stack Overflow用户
提问于 2022-03-26 14:42:38
回答 1查看 164关注 0票数 0

我有个反应-本土项目。我已经升级到最近的react和react-原生版本,甚至和项目中的所有其他包一样。由于React 17带来了JSX (https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#manual-babel-setup),我按照这些步骤在我的应用程序中使用它。

但至少它不像预期的那样起作用。

我想知道新的JSX转换功能是否不适用于react原生应用程序,但只适用于一般的?!

这是我的babel.config.js:

代码语言:javascript
复制
module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    [
      '@babel/plugin-proposal-decorators',
      {
        legacy: true,
      },
    ],
    [
      '@babel/plugin-transform-react-jsx',
      {
        runtime: 'automatic',
      },
    ],
    'react-native-reanimated/plugin',
  ],
};

这是我的eslintrc.json:

代码语言:javascript
复制
{
  "parser": "@babel/eslint-parser",
  "env": {
    "browser": true,
    "react-native/react-native": true,
    "es6": true,
    "node": true
  },
  "extends": [
    "@react-native-community",
    "plugin:react/recommended",
    "airbnb-base",
    "prettier/react"
  ],
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 2018,
    "sourceType": "module"
  },
  "plugins": [
    "react",
    "react-native",
    "prettier"
  ],
  "rules": {
    "react/jsx-uses-react": "off",
    "react/react-in-jsx-scope": "off",
    "object-curly-newline": 0,
    "max-len": [
      "error",
      {
        "code": 100,
        "comments": 150,
        "ignoreTrailingComments": true,
        "ignoreUrls": true
      }
    ],
    "indent": [
      "warn",
      2
    ],
    "linebreak-style": [
      "error",
      "unix"
    ],
    "quotes": [
      2,
      "single",
      {
        "avoidEscape": true,
        "allowTemplateLiterals": true
      }
    ],
    "semi": [
      "error",
      "always"
    ],
    "react-native/no-unused-styles": 2,
    "react-native/split-platform-components": 2,
    "react-native/no-inline-styles": 2,
    "react-native/no-color-literals": 2,
    "react-native/no-raw-text": 2,
    "prettier/prettier": [
      "warn",
      {
        "endOfLine": "auto",
        "bracketSpacing": true
      }
    ]
  }
}
EN

回答 1

Stack Overflow用户

发布于 2022-03-26 14:57:47

您可以尝试此解决方案,以使其与本机react一起工作。

https://github.com/facebook/metro/issues/646#issuecomment-799174473

因此,通过在babel配置文件中同时使用useTransformReactJSXExperimental和运行时设置。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71629017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档