react-native-reanimated: Compiling JS failed: Invalid expression Buffer size

Description

Starting with Version 3.4.0 I get the error Compiling JS failed: 232124:78:invalid expression Buffer size 17924054 starts with: 766172205f5f42554444c455f535441 (see screenshot). I stayed with version 3.3.0 for as long as I could (up to React Native 0.71) but now that I’m finally upgrading my app to React Native 0.73 I need to upgrade to at least 3.6.0 and desperately need a fix for this.

Simulator Screenshot - iPhone 15 Pro - 2024-03-13 at 13 56 55

Steps to reproduce

  1. Install “react-native-reanimated” >= 3.4.0
  2. Run app on iOS

Snack or a link to a repository

n.a.

Reanimated version

3.8.0

React Native version

0.73.6

Platforms

Android, iOS

JavaScript runtime

Hermes

Workflow

React Native

Architecture

Paper (Old Architecture)

Build type

Debug app & dev bundle

Device

iOS simulator

Device model

iPhone 15 Pro (iOS 17)

Acknowledgements

Yes

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (2 by maintainers)

Most upvoted comments

@DanielKuhn I looked into your package.json and yarn.lock, created new RN App using 0.73.6, copied your package.json and yarn.lock there, removed all irrelevant dependencies and everything worked fine.

From what I see react-native-svg-transfomer adds a bunch of babel plugins, however I don’t know if you are actually using them - could it possible be the culprit?

Unfortunately, since there seems to be no problems with brand new apps it seems that the issue is somewhere on your side. There are some additional steps I would suggest here:

  • Create a brand new React Native App npx react-native init App --version 0.73.6, add Reanimated, use it and see if the problem persists - if it does, then there’s something wrong with your machine configuration.
  • Clear your yarn cache in case you have overrode some packages - yarn cache clean.
  • You can actually use generated js files instead of source typescript files. All you need is the following change in your metro.config.js:
diff --git a/metro.config.js b/metro.config.js
index ad8f87b..feaf6fb 100644
--- a/metro.config.js
+++ b/metro.config.js
@@ -6,6 +6,10 @@ const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
  *
  * @type {import('metro-config').MetroConfig}
  */
-const config = {};
+const config = {
+  resolver: {
+    resolverMainFields: ['main', 'react-native'],
+  },
+};
 
 module.exports = mergeConfig(getDefaultConfig(__dirname), config);

Closing the issue since its irreproducible and seems to be tied to the user’s environment issues. I’m happy to reopen the issue once a reliable reproduction is available.

I for my part forked react-native-reanimated at version 3.8.1 and simply pointed “react-native” to “lib/module/index” in package.json in the fork. I found changing resolverMainFields globally in my app too risky because I don’t know which side-effects this might have in other packages and the typescript compilation mentioned here is only a problem in react-native-reanimated.

This seems like outdated @babel/preset-typescript potentially. Try to upgrade it (regenerating yarn.lock should do the trick).