【问题标题】:React Native - unexpected token static propTypes when running assmbleRelease, babel plugin doesnt workReact Native - 运行 assembleRelease 时出现意外的令牌静态 propTypes,babel 插件不起作用
【发布时间】:2019-08-06 17:23:27
【问题描述】:

我正在尝试在 React Native 中使用 “react-native run-android --variant=release”或 来自 ./android: "./gradelw assmbleRelease"

我不断收到以下错误:

> :app:bundleReleaseJsAndAssets

 ERROR  Failed to compile.

./node_modules/native-base-shoutem-theme/src/StyleProvider.js 10:19
Module parse failed: Unexpected token (10:19)
You may need an appropriate loader to handle this file type.
|  */
| export default class StyleProvider extends React.Component {
>   static propTypes = {
|     children: PropTypes.element.isRequired,

...

我已经安装了这个插件: https://babeljs.io/docs/en/next/babel-plugin-proposal-class-properties.html

并将其添加到我的 babel.config.js 中:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],   
  plugins: [
    '@babel/plugin-proposal-class-properties'
  ]
};

我也尝试过创建一个 .babelrc 文件并进行设置。没用。 我尝试通过 package.json 配置 babel 也没有成功。

我试过了

"react-native start -- --reset-cache"

但没有任何帮助。我不断收到同样的错误。 我知道 babel.config.js 正在被读取,因为如果我乱用它,我会发现构建由于其他原因而失败。 但奇怪的是,如果我完全删除文件,我仍然会收到原始错误(缺少“静态 propTypes”的东西)。

为什么插件不起作用?

【问题讨论】:

    标签: javascript react-native babeljs


    【解决方案1】:

    不知道为什么会发生这种情况,但删除“运输”就可以了。

    "npm 卸载 --save-dev 运输" 并删除 app/build.gradle 中添加的配置:

    project.ext.react = [
        cliPath: "node_modules/haul/bin/cli.js"
    ]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-31
      • 2016-07-01
      • 1970-01-01
      • 2017-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-10
      相关资源
      最近更新 更多