React Native初学者项目捆绑失败,出现意外令牌错误

我正在尝试使用https://facebook.github.io/react-native/docs/getting-started.html上的说明为Android创build我的第一个React Native应用程序。 设置依赖关系并连接我的Android设备后,我跑了

react-native init app cd app react-native run-android 

这将启动React Packager,该错误与此错误捆绑失败:

错误:捆绑失败:“TransformError:/Users/luky/dev/app/index.android.js:Unexpected token)(处理预设:\”/ Users / luky / dev / app / node_modules / babel-preset-react-本地/ index.js \ “)”

我在用:

  • OSX El Capitan 10.11.6。
  • 节点版本6.9.2
  • react-native版本0.47.1。

我将生成的项目(包括node_modules)推送到Github,以防万一: https : //github.com/luky1971/react-native-app

有谁知道为什么我可能会得到一个意外的令牌错误? 任何帮助将不胜感激!

我得到了同样的东西,它看起来像babel预设为反应本地的最新版本有一些错误(版本3.0.0)。 我进入我的package.json并用这个replace了最新版本:

“babel-preset-react-native”:“2.1.0”。

然后我删除了node_modules目录并运行npm install,它工作。

安装babel-preset-react-native@2.1.0并运行该项目。

在当前的项目中,这样做…

yarn remove babel-preset-react-native
yarn add babel-preset-react-native@2.1.0

这对我有用,我希望它也适合你。

你可以在这里find更多关于错误的信息https://github.com/facebook/react-native/issues/15513#issuecomment-322824346

 Looking for JS files in /Users/admin/Desktop/CoinMarketCap React packager ready. Loading dependency graph, done. Bundling `index.ios.js` [development, non-minified, hmr disabled] 0.0% (0/1), failed. error: bundling failed: "TransformError: /Users/admin/Desktop/CoinMarketCap/index.ios.js: Unexpected token ) (While processing preset: \"/Users/admin/Desktop/CoinMarketCap/node_modules/babel-preset-react-native/index.js\")" iMac-D001:CoinMarketCap admin$ react-native --v react-native-cli: 2.0.1 react-native: 0.47.1 

为我修复: https : //github.com/facebook/react-native/issues/15545

 iMac-D001:CoinMarketCap admin$ npm uninstall babel-preset-react-native iMac-D001:CoinMarketCap admin$ npm install babel-preset-react-native@2.1.0 

我克隆你的项目。 它工作正常。 您可以删除node_modules文件夹,然后删除npm_install。 它会正常工作。

尝试删除根目录中的.babelrc文件。 或者重命名它。 然后重新运行“react-native run-android”命令。 这对我有效。 祝你好运。