首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >react-native-web:无法编译(react-native-vector-icons)

react-native-web:无法编译(react-native-vector-icons)
EN

Stack Overflow用户
提问于 2019-06-25 16:56:01
回答 1查看 1.5K关注 0票数 2

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

代码语言:javascript
运行
复制
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文件下有这个部分

代码语言:javascript
运行
复制
{
  "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 }]
  ]
}

有人能帮上忙吗?

EN

回答 1

Stack Overflow用户

发布于 2019-10-08 22:33:24

将.babelrc配置转移到webconfig对我来说很有效,webconfig如下所示

代码语言:javascript
运行
复制
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'
  }
]
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56750269

复制
相关文章

相似问题

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