reactjs - react-native-web:编译失败(react-native-vector-icons)

标签 reactjs react-native babeljs react-native-web react-native-vector-icons

构建react-native-web时出现如下错误:

ERROR in ./node_modules/react-native-vector-icons/lib/create-icon-set.js 43:21
Module parse failed: Unexpected token (43:21)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| 
|   class Icon extends PureComponent {
>     static propTypes = {
|       allowFontScaling: PropTypes.bool,
|       name: IconNamePropType,
 @ ./node_modules/react-native-vector-icons/AntDesign.js 6:0-50 9:16-29
 @ ./src/containers/news/index.js
 @ ./src/App.js
 @ ./src/index.js

我在 .babelrc 文件下有这个部分

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react",
    "@babel/preset-typescript",
    "module:metro-react-native-babel-preset"
  ],
  "plugins": [
    ["module-resolver", {
      "alias": {
        "^react-native$": "react-native-web"
      }
    }],
    "@babel/plugin-transform-runtime",
    ["@babel/plugin-proposal-class-properties", { "loose": true }]
  ]
}

有人能帮忙吗?

最佳答案

将 .babelrc 配置移动到 webconfig 对我有用,webconfig 看起来像这样

rules: [
  {
    test: /\.(js|jsx)$/,
    loader: 'babel-loader',
    options: {
      presets: [
        '@babel/preset-env',
        "@babel/preset-react",
        {
          plugins: [
            '@babel/plugin-proposal-class-properties'
          ]
        }
      ]
    },
  },
  {
    test: /\.css$/,
    loader: 'style-loader!css-loader'
  }
]

关于reactjs - react-native-web:编译失败(react-native-vector-icons),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56750269/

相关文章:

javascript - Intellij 插件 : AirBnB ESLint w/React

reactjs - 当只更新部分状态时,我需要克隆多深的状态?

javascript - 无限滚动不会在 React/Redux 中保留以前的项目

android - React Native Gradle 失败并显示 `java.lang.NullPointerException (no error message)`

vue.js - Vue CLI 3 不会将供应商转换为 ES5

javascript - ReactCSSTransitionGroup 不留任何影响

react-native - 使用 Redux 工具包中的 createEntityAdapter 时如何将实体作为类组件中的数组获取?

javascript - 如何从 AsyncStorage 获取多个键,然后将这些键添加到数组中?

javascript - npx babel 没有从 babel.config.js 读取配置

javascript - babel es5 到 es6 在导入时将 less 扩展转换为 css