SyntaxError: You can only use Class Properties when the 'classProperties' plugin is enabled

独自空忆成欢 提交于 2019-12-30 19:05:27

问题


I am getting the following syntax error when I initialize an app using react-native init MyApp

    SyntaxError: /Users/MyAccount/RNProjects/app/node_modules/react-native/packager/react-packager/src/node-haste/index.js: You can only use Class Properties when the 'classProperties' plugin is enabled. (389:2)
  387 |   }
  388 |
> 389 |   static Cache;
      |   ^
  390 |   static Module;
  391 |   static Polyfill;
  392 |   static getAssetDataFromName;
    at Parser.pp$5.raise (/Users/MyAccount/RNProjects/app/node_modules/babylon/lib/index.js:4380:13)

I have no idea why this is happening all of a sudden. It was working all fine before. I guess I deleted some config files by mistake while tinkering.


回答1:


Update

They have updated the package so remove your node modules and reinstall them. rm -rf node_modules and npm install More info

I was installing the AwesomeProject from getting started.

$ rm -rf AwesomeProject/
$ react-native init AwesomeProject

And it worked!

Original

An issue has been filed: https://github.com/facebook/react-native/issues/12542

npm uninstall babylon && npm install babylon@6.15.0 or update the package.json file to include "babylon": "6.15.0"




回答2:


In my case (on windows7), python was not installed. After installing Python2 react-native init command is working fine.



来源:https://stackoverflow.com/questions/42417171/syntaxerror-you-can-only-use-class-properties-when-the-classproperties-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!