react-native - 与 native react 的巴比伦语法错误

标签 react-native syntax-error babeljs babylonjs

我在React Native中遇到了这个看起来很神秘的错误。尝试使用npm重新安装我的软件包并检查我自己的代码语法,但没有任何进展。

控制台日志仅引用此文件:node_modules/babylon/lib/index.js
可能的原因是什么,以及如何获取有关此错误的更多调试信息?

~/ReactNativeProject/node_modules/react-native/packager ~
Scanning 576 folders for symlinks in /Users/user/ReactNativeProject/node_modules (15ms)
 ┌────────────────────────────────────────────────────────────────────────────┐ 
 │  Running packager on port 8081.                                            │ 
 │                                                                            │ 
 │  Keep this packager running while developing on any JS projects. Feel      │ 
 │  free to close this tab and run your own packager instance if you          │ 
 │  prefer.                                                                   │ 
 │                                                                            │ 
 │  https://github.com/facebook/react-native                                  │ 
 │                                                                            │ 
 └────────────────────────────────────────────────────────────────────────────┘ 
Looking for JS files in
   /Users/user/ReactNativeProject 

[01/31/2017, 18:22:20] <START> Initializing Packager
[01/31/2017, 18:22:20]         HMR Server listening on /hot

React packager ready.

[01/31/2017, 18:22:21] <START> Building Haste Map
[01/31/2017, 18:22:21] <END>   Building Haste Map (248ms)
[01/31/2017, 18:22:21] <END>   Initializing Packager (1083ms)
[01/31/2017, 18:22:38] <START> Requesting bundle
                               bundle_url: /index.ios.bundle?platform=ios&dev=true&minify=false&hot=true
[01/31/2017, 18:22:38] <START> Transforming files
transformed 422/460 (92%)/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:4336
  throw err;
  ^

SyntaxError: Unexpected token (23:1)
    at Parser.pp$5.raise (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:4333:13)
    at Parser.pp.unexpected (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:1705:8)
    at Parser.pp$3.parseIdentifier (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:4211:10)
    at Parser.pp$3.parsePropertyName (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:4031:96)
    at Parser.pp$3.parseObj (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3947:12)
    at Parser.pp$3.parseExprAtom (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3639:19)
    at Parser.pp$3.parseExprSubscripts (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3414:19)
    at Parser.pp$3.parseMaybeUnary (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3394:19)
    at Parser.pp$3.parseExprOps (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3324:19)
    at Parser.pp$3.parseMaybeConditional (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3301:19)
transformed 442/506 (87%)/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:4336
  throw err;
  ^

SyntaxError: Unexpected token (23:1)
    at Parser.pp$5.raise (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:4333:13)
    at Parser.pp.unexpected (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:1705:8)
    at Parser.pp$3.parseIdentifier (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:4211:10)
    at Parser.pp$3.parsePropertyName (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:4031:96)
    at Parser.pp$3.parseObj (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3947:12)
    at Parser.pp$3.parseExprAtom (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3639:19)
    at Parser.pp$3.parseExprSubscripts (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3414:19)
    at Parser.pp$3.parseMaybeUnary (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3394:19)
    at Parser.pp$3.parseExprOps (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3324:19)
    at Parser.pp$3.parseMaybeConditional (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3301:19)
transformed 483/542 (89%)/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:4336
  throw err;
  ^

SyntaxError: Unexpected token (23:1)
    at Parser.pp$5.raise (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:4333:13)
    at Parser.pp.unexpected (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:1705:8)
    at Parser.pp$3.parseIdentifier (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:4211:10)
    at Parser.pp$3.parsePropertyName (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:4031:96)
    at Parser.pp$3.parseObj (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3947:12)
    at Parser.pp$3.parseExprAtom (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3639:19)
    at Parser.pp$3.parseExprSubscripts (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3414:19)
    at Parser.pp$3.parseMaybeUnary (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3394:19)
    at Parser.pp$3.parseExprOps (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3324:19)
    at Parser.pp$3.parseMaybeConditional (/Users/user/ReactNativeProject/node_modules/babylon/lib/index.js:3301:19)
transformed 691/694 (100%)

最佳答案

问题出在React Native组件之一的render()方法上,以及在错误的地方使用了散布运算符,

render(){
    return (
      <View>
        {...this.props.children}
      </View>
    )
  }

必须更改为
render(){
    return (
      <View>
        {this.props.children}
      </View>
    )
  }

关于react-native - 与 native react 的巴比伦语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41963916/

相关文章:

reactjs - Webpack webpackChunkName 魔术注释不起作用

express - 使用expo表达服务器时没有请求头来源

react-native - 抽屉导航不会像堆栈导航那样更新组件

java - If Else 赋值运算符问题 - Java

python - python-源代码字符串不能包含空字节

javascript - 自耕农 : angular-fullstack-generator cannot find module 'babel-runtime/helpers/interop-require-default'

javascript - 意外的 token 导出 webpack

android - 带有后退按钮的 react 导航重新渲染 View

react-native - 在 React Native 中的数组或对象内部时,i18n 无法正确翻译

function - Python return语句行不通吗?