React Native-运行assmbleResase时出现意外的令牌静态propTypes,babel插件不起作用

时间:2019-03-15 15:24:23

标签: javascript react-native babel

我正在尝试使用以下任一方法在React Native中编译发行版apk “ 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,因为如果我弄乱了babel.config.js,我会发现由于其他原因该构建失败。 但是奇怪的是,如果我完全删除文件,仍然会得到原始错误(缺少“静态propTypes”)。

为什么插件不起作用?

1 个答案:

答案 0 :(得分:0)

不知道为什么会这样,但是消除“拖拉”就可以了。

“ npm卸载--save-dev拖拉” 并删除app / build.gradle中添加的配置:

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