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

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…

About this issue

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

Most upvoted comments

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 !

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.

Upgrading JavascriptCore works, but it is not supported before SDK 21 (Android < 5.0). And I have the problem too on iOS 9.3.

Is there a way to use Typescript compiler (the one used by react-native-typescript-transformer ?) and not Babel 7 one to compile Typescript ? I tried to find a solution in Metro issues and documentation, but I found nothing. Do we have to give up Typescript in React Native for the moment ?

I already had to solve problems with namespaces and enums because of Babel 7. And now one more problem 👎