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

Created on 12 Sep 2018  ·  23Comments  ·  Source: facebook/react-native

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..

Bug Locked

Most helpful comment

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 !

All 23 comments

It looks like you are using an older version of React Native. Please update to the latest release, v0.57 and verify if the issue still exists.

The ":rewind:Old Version" label will be removed automatically once you edit your original post with the results of running react-native info on a project using the latest release.

I have a similar issue with babel parsing in 0.57.0, but on only on windows and with react-navigation added. I skipped the previous release, because it was broken on Windows, really need to update my project to 0.57.

This also happens to me with react-navigation. Not importing createStackNavigator at least does not cause this issue. It manifests differently for me though:

TypeError: comments is not iterable
    at PluginPass.Program (/path/node_modules/@babel/plugin-transform-flow-strip-types/lib/index.js:58:31)

@ajcrites I was getting the same error but switching to node 8.3, I get the error below now

Cannot read property 'Symbol(Symbol.iterator)' of null

This happens only if I have images. If I don't reference the image assets from my code, it works fine

@ajcrites see this issue for TypeError: comments is not iterable: https://github.com/react-navigation/react-navigation/issues/4983#issuecomment-420892313

@yurykorzun I'm using react-native-navigation, so not sure if this is caused by the navigation library

You update RN from 0.55 to 0.57, babel has a big upgrade from RN 0.56, our team also found some navigation issues, I think you should open an issue ticket to navigation project.

I just did a shot in the wild, updating the JavascriptCore using JSC-android-buildscripts and now it runs fine on android!

I'm suspecting that the Typescript compiled by Babel is not compatible with the current JSC, but I've no idea where to start looking.

One thing I also noticed is that the JS output by http://localhost:8081/index.delta?platform=android&dev=true&minify=false contains \n characters instead of actual newlines. This makes finding the location of the original error a lot more difficult

https://github.com/babel/babel/issues/8692
resolved in 7.1.0 version

I'm getting a similar issue:

error: bundling failed: SyntaxError: /Users/me/Code/myApp/react/sundown/src/screens/public/login.tsx: Unexpected token, expected ")" (22:46)

  20 |     emailChanged: (text: string) => {},
  21 |     passwordChanged: (text: string) => {},
> 22 |     loginUser: ({ email, password, navigator }: { email: string, password: string, navigator: Navigator }) => {},
     |                                               ^
  23 |     validation: Function,
  24 |     useBiometrics: { wasAsked: boolean, use: boolean }
  25 | }

with react-native 0.56.1 -> 0.57.1 and typescript 2.9.2

... for an update with no breaking changes, it seems to be breaking a lot of things. :p

re: Babel upgrade... srsly?

https://babeljs.io/docs/en/v7-migration
https://babeljs.io/docs/en/config-files#6x-vs-7x-babelrc-loading

... it's a short book. Also I tried to do the steps I found there, and it didn't seem to resolve my issue. I ended up stashing my changes.

Any updates? We're unable to upgrade to 0.57 because of this.

@animaonline Upgrading JavascriptCore did the trick for me...

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 👎

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 !

@chawax @freakinruben
For those who are trying to configure ts with expo-31:
Check our boilerplate. This repo contains all initial configurations to make things working with new expo-31, babel 7, typescript and jest.

Have anyone that's still having this issue tried upgrading to Babel 7.1.0 or newer?

It seems like there was a problem that prevented the TypeScript transformer from handing over default parameters to the next transformer that made it work on older JS runtimes. That's why it crashes specifically on Android when using an old JSC that doesn't support the default arguments syntax.

Upgrading to Babel 7.1.0 should fix the issue, while upgrading to a newer JSC or using the non-babel TypeScript converter should work around it.

Would be great if someone could confirm that it's fixed in Babel 7.1.0 ❤️

It won't solve other problems with Babel 7 and Typescript, support of namespaces for example. And from what I understood it comes from architectural constraints, so it won't be solved soon. If Babel 7 doesn't support the whole Typescript, it can't be the right choice for React Native with Typescript.

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.

@LinusU Actually I use Swagger code generator to generate a API client. And this generated code uses namespaces ;) I tried to patch the Swagger code generator but it's not that easy and time consuming. I used react-native-typescript-transformer as you suggested and it works well (I have posted about this a few posts before) and it works well anyway. Just hope it will still be maintained.

I had the same cryptic message, but was unrelated. If you happen to use Typescript constructor parameter assignment, it won't work, see babel/babel/issues/8752

The new JSC landed on master last month.

@chawax I patched the swagger codegen, it's only a few lines of code
This code removes namespaces and just creates long names for the enums
There should be no name collisions in this case

I might create a pull request for swagger codegen to have a ts-no-namespace generator, but for now you can simply try this:
https://github.com/danielwinkler/swagger-codegen/commit/a519f740475800edda5f7d61ebaef2292d898efe

Was this page helpful?
0 / 5 - 0 ratings