React Native Starter项目捆绑失败并出现意外令牌错误 [英] React Native starter project bundling fails with Unexpected Token error

查看:70
本文介绍了React Native Starter项目捆绑失败并出现意外令牌错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用

I'm trying to create my first React Native app for Android using the instructions on https://facebook.github.io/react-native/docs/getting-started.html. After setting up the dependencies and connecting my Android device, I ran

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

这将启动React Packager,该打包器因以下错误而无法捆绑:

This starts the React Packager, which fails to bundle with this error:

错误:捆绑失败:"TransformError:/Users/luky/dev/app/index.android.js:意外令牌)(处理预设:\"/Users/luky/dev/app/node_modules/babel-preset -react-native/index.js \)"

error: bundling failed: "TransformError: /Users/luky/dev/app/index.android.js: Unexpected token ) (While processing preset: \"/Users/luky/dev/app/node_modules/babel-preset-react-native/index.js\")"

我正在使用:

  • OSX El Capitan 10.11.6.
  • 节点版本6.9.2
  • 本机版本0.47.1.

如果有帮助,我将生成的项目(包括node_modules)推送到Github: https://github.com/luky1971/react-native-app

I pushed my generated project, including node_modules, to Github in case it helps: https://github.com/luky1971/react-native-app

有人知道我为什么会收到意外的令牌错误吗?任何帮助将不胜感激!

Does anyone know why I might be getting an Unexpected token error? Any help would be greatly appreciated!

推荐答案

我也有同样的想法,看来React Native的babel预设的最新版本存在一些错误(版本3.0.0).我进入package.json并用以下代码替换了最新版本:

I got the same thing, it looks like the latest version of the babel preset for react native has some bugs (version 3.0.0). I went into my package.json and replaced the latest version with this:

"babel-preset-react-native":"2.1.0".

"babel-preset-react-native": "2.1.0".

然后我删除了node_modules目录并运行了npm install并成功了.

then I deleted the node_modules directory and ran npm install and it worked.

这篇关于React Native Starter项目捆绑失败并出现意外令牌错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆