Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 855
ankushlokhande Avatar asked Jun 28 '26 20:06

ankushlokhande


2 Answers

In my case, the issue was with @react-native/babel-preset, which was not added inside the devDependencies. I added it to the devDependencies with version 0.76.1, and it worked for me.

"devDependencies": {
       "@react-native/babel-preset": "^0.76.1",
 }

Reference: carloscuesta/react-native-error-boundary#897.

like image 126
Tejas Bitale Avatar answered Jul 01 '26 13:07

Tejas Bitale


I managed to fix this issue by replacing presets: ['module:metro-react-native-babel-preset'], with presets: ['module:@react-native/babel-preset'], in both babel.config.js & .babelrc

like image 31
Samuel Rodrigues Avatar answered Jul 01 '26 13:07

Samuel Rodrigues



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!