[RN 0.57] JS Exception: Unexpected token '='.

See original GitHub issue

Environment

$ react-native info

  React Native Environment Info:
    System:
      OS: macOS High Sierra 10.13.6
      CPU: x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
      Shell: 5.5.1 - /usr/local/bin/zsh
    Binaries:
      Node: 8.11.2 - ~/.nvm/versions/node/v8.11.2/bin/node
      Yarn: 1.9.4 - /usr/local/bin/yarn
      npm: 5.6.0 - ~/.nvm/versions/node/v8.11.2/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
      Android SDK:
        Build Tools: 23.0.1, 25.0.2, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.3
        API Levels: 23, 25, 26, 27
    IDEs:
      Android Studio: 3.1 AI-173.4819257
      Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
    npmPackages:
      react: ^16.5.0 => 16.5.0
      react-native: 0.57.0 => 0.57.0

Description

I’ve been trying to upgrade from RN 0.55 to 0.57. So far I got almost everything working except android:

  • ts-jest ✅
  • react-native bundle ✅ (react-native bundle --platform android --dev false --entry-file index.js --bundle-output index.bundle)
  • iOS debug build ✅
  • iOS release build ✅
  • Android debug build ✅
  • Android release build ✅
  • Running iOS debug/release build ✅
  • Running android debug/release build ❌

Error from logcat:

E ReactNativeJNI: Got JS Exception: Unexpected token '='. Expected a ')' or a ',' after a parameter declaration. (http://10.0.3.2:8081/index.delta?platform=android&dev=true&minify=false:145698)
E unknown:ReactNative: Exception in native call from JS
E unknown:ReactNative: com.facebook.react.devsupport.JSException: Unexpected token '='. Expected a ')' or a ',' after a parameter declaration. (http://10.0.3.2:8081/index.delta?platform=android&dev=true&minify=false:145698)
E unknown:ReactNative: 	at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
E unknown:ReactNative: 	at android.os.Handler.handleCallback(Handler.java:789)
E unknown:ReactNative: 	at android.os.Handler.dispatchMessage(Handler.java:98)
E unknown:ReactNative: 	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
E unknown:ReactNative: 	at android.os.Looper.loop(Looper.java:164)
E unknown:ReactNative: 	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
E unknown:ReactNative: 	at java.lang.Thread.run(Thread.java:764)
E unknown:ReactNative: Caused by: com.facebook.jni.CppException: Unexpected token '='. Expected a ')' or a ',' after a parameter declaration. (http://10.0.3.2:8081/index.delta?platform=android&dev=true&minify=false:145698)
E unknown:ReactNative: 	... 7 more
E unknown:ReactNative: Unable to launch redbox because react activity is not available, here is the error that redbox would've displayed: Unexpected token '='. Expected a ')' or a ',' after a parameter declaration. (http://10.0.3.2:8081/index.delta?platform=android&dev=true&minify=false:145698)
E unknown:ReactNative:
E unknown:ReactNative: Unexpected token '='. Expected a ')' or a ',' after a parameter declaration. (http://10.0.3.2:8081/index.delta?platform=android&dev=true&minify=false:145698)
E unknown:ReactNative:
D ReactNative: CatalystInstanceImpl.destroy() start
D ReactNative: CatalystInstanceImpl.destroy() end

Similar error happens for release build. I’ve tried to look up the token on which it is tripping but there is no = sign at column 145698

Reproducible Demo

Not sure how to create a reproducable demo at this point since runs fine on iOS and bundling for android also works…

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:23 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
chawaxcommented, Nov 14, 2018

One gave me the solution here ! You have to change your rn-cli.config.js file :

module.exports = {
  transformer: {
    babelTransformerPath: require.resolve('react-native-typescript-transformer'),
  },
}

This way it doesn’t use Babel 7 Typescript transformer but the former React Native Typescript transformer that supports namespaces and enums !

3reactions
LinusUcommented, Nov 17, 2018

I personally think that the limitations of Babels TypeScript support is extremely small, and not something that you run into, especially since it only affects the code in your project and not the code of your dependencies. I have yet to see a project that actually uses namespaces since we have modules, or maybe I’m missing something?

That being said, there is nothing stopping anyone from using the official TypeScript compiler together with React Native. We didn’t change anything to make that harder. In fact, we just upgraded Babel and the new Babel has support for TypeScript.

@chawax if you feel that the Babel support for TypeScript is inadequate, you can use tsc with React Native using this package: https://github.com/ds300/react-native-typescript-transformer

I do recommend trying out Babel though since the limitations are very small, and it will be faster since it doesn’t have to pass the code first thru tsc and then babel.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected identifier jest & babel 7 & react-native 0.56 - Stack ...
I get SyntaxError: Unexpected identifier error. Details in below. Can you help me, please? This is my devDependencies. "@babel/core": "^7.0.0 ...
Read more >
[Windows] "Unexpected token '...'. Expected a ... - Bountysource
Expected a property name." Babel configuration issue in RN 0.57. ... but I tried to upgrade to 0.57 rc4 and got a babel...
Read more >
Jest encountered an unexpected token with react-native ...
Coding example for the question Jest encountered an unexpected token with react-native-React Native.
Read more >
Mocking RN modules | React Made Native Easy
Like other testing frameworks, Jest also supports mocking modules, both Node.js modules and custom JS modules. Most of the React Native specific utilities ......
Read more >
RN项目启动报Unhandled JS EXception:SyntaxError解决方法
Unhandled JS Exception: Unexpected identifier '_classCallCheck'. import call expects exactly one arg. 最新发布 · weixin_42349568的博客.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found