Search code examples
androidreact-nativenode-modules

React Native: SyntaxError in node_module -> EventEmitter.js: Unexpected Token, Expected "]"


I'm upgrading my React Native project to a newer version. What I’ve done for this:

  1. Created a new React Native project using the latest version.
  2. Installed all the required packages that were in the old project to test for compatibility. None of the packages caused crashes in the new project.
  3. Imported my actual project code into the new folder.

When I try to run the project, I get the error in the node_modules folder:


 ERROR  SyntaxError: [ROOT_FOLDER]/node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js: 
Unexpected token, expected "]" (39:5)

  37 |
  38 | type Registry<TEventToArgsMap: {...}> = {
> 39 |   [K in keyof TEventToArgsMap]: Set<Registration<TEventToArgsMap[K]>>,
     |      ^
  40 | };
  41 |
  42 | /**

Steps Tried:

  • Cleaned the project cache
  • Reinstall the all packages
  • Build android project via Android Studio

Search on the internet, found simailar issue but not related to mine. https://github.com/puppeteer/puppeteer/issues/10509


Solution

  • If you updated your react native project, check your @react-native/etc

    Config file:
    Config file

    and see it's the same as the one up top, there's an update at react native 0.76.4 which fixes that issue

    Source: https://github.com/facebook/react-native/issues/46355

    Edit: Found this because was searching for the same error myself, this fixed it for me