反应原生的Babylon语法错误

时间:2017-01-31 17:33:15

标签: react-native syntax-error babeljs babel 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%)

1 个答案:

答案 0 :(得分:1)

问题在于其中一个React Native组件的render()方法以及在错误的位置使用扩展运算符,

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

必须改为

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