React native : Failed to construct transformer: Error: Cannot create a string longer than 0x1fffffe8 characters

Viewed 13221

hear is the screenshot of the error

package.json

{
  "name": "project",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@react-native-community/async-storage": "^1.12.0",
    "@react-native-community/clipboard": "^1.2.3",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-navigation/drawer": "^5.9.0",
    "@react-navigation/native": "^5.7.3",
    "@react-navigation/stack": "^5.9.0",
    "@twotalltotems/react-native-otp-input": "^1.3.11",
    "jetifier": "^1.6.6",
    "react": "16.13.1",
    "react-native": "^0.63.2",
    "react-native-barcode-builder": "^2.0.0",
    "react-native-biometrics": "^2.1.4",
    "react-native-chart-kit": "^6.6.1",
    "react-native-gesture-handler": "^1.7.0",
    "react-native-image-picker": "^2.3.3",
    "react-native-localization": "^2.1.6",
    "react-native-paper": "^4.0.1",
    "react-native-reanimated": "^1.13.0",
    "react-native-safe-area-context": "^3.1.6",
    "react-native-screens": "^2.10.1",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^12.1.0",
    "react-native-swipe-list-view": "^3.2.3",
    "react-native-vector-icons": "^7.0.0"
  },
  "devDependencies": {
    "@babel/core": "7.11.4",
    "@babel/runtime": "7.11.2",
    "@react-native-community/eslint-config": "1.1.0",
    "babel-jest": "25.5.1",
    "eslint": "6.8.0",
    "jest": "25.5.4",
    "metro-react-native-babel-preset": "0.59.0",
    "miragejs": "^0.1.40",
    "react-test-renderer": "16.13.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

i did't fonund any answers related this except this : https://github.com/facebook/react-native/issues/28189

but it won't work for me...

myapp successfully install on android emulator but stuck at splash screen ...

the app works fine in my office computer but it did't work on my own computer

my node version : v14.10.0

so please help me.

11 Answers

I've tried to log the file that causing the error, but console.log wasn't working. I come up with a quick hack to throw filePath then I've saw that a zip file, that I keeped as a backup, was the issue.

For some way react doesn't liked it so I have to move it outside of the project folder

I was running into the same problem.

 warning: the transform cache was reset.                                                                          
                 Welcome to React Native!                                                                        
                Learn once, write anywhere 
Failed to construct transformer:  Error: Cannot create a string longer than 0x1fffffe8 characters                
    at Object.slice (buffer.js:608:37)                                                                           
    at Buffer.toString (buffer.js:805:14)                                                                        
    at Object.readFileSync (fs.js:421:41)                                                                        
    at getContent (J:\expoProjects\rn-cnn\node_modules\metro\node_modules\jest-haste-map\build\worker.js:149:41) 
    at Object.<anonymous> (J:\expoProjects\rn-cnn\node_modules\metro\node_modules\jest-haste-map\build\worker.js:
199:9)                                                                                                           
    at Generator.next (<anonymous>)                                                                              
    at asyncGeneratorStep (J:\expoProjects\rn-cnn\node_modules\metro\node_modules\jest-haste-map\build\worker.js:
78:24)                                                                                                           
    at _next (J:\expoProjects\rn-cnn\node_modules\metro\node_modules\jest-haste-map\build\worker.js:98:9)        
    at J:\expoProjects\rn-cnn\node_modules\metro\node_modules\jest-haste-map\build\worker.js:103:7               
    at new Promise (<anonymous>) {                                                                               
  type: 'Error',                                                                                                 
  code: 'ERR_STRING_TOO_LONG'                                                                           

I solved the error by changing the node version to v14+ and then reverting back to the old version of node v10.15.3.

I've run into the exact same error. Turns out it was an auto-generated big file from gradle (> 700MB) inside "android.gradle\6.0.1\executionHistory"

For others having the same problem, and looking for a way to debug:

  • Edit /node_modules/jest-haste-map/build/worker.js

  • Wrap readFileSync in a try...catch, like this:

  const getContent = () => {
    if (content === undefined) {
      try {
        content = fs().readFileSync(filePath, 'utf8');
      } catch (err) {
        throw new Error(`error readFileSync ${filePath} : ${err.message}`);
      }
    }

    return content;
  };
  • (re)start metro bundler:

/node_modules/react-native/scripts/launchPackager.command; exit

My output:

To reload the app press "r"
To open developer menu press "d"

Failed to construct transformer:  Error: error readFileSync <my project path>/some/big/file/that/caused/error : Cannot create a string longer than 0x1fffffe8 characters
    at getContent (<my project path>/node_modules/jest-haste-map/build/worker.js:133:15)
    at Object.worker (<my project path>/node_modules/jest-haste-map/build/worker.js:162:23)
    at execFunction (<my project path>/node_modules/jest-worker/build/workers/processChild.js:145:17)
    at execHelper (<my project path>/node_modules/jest-worker/build/workers/processChild.js:124:5)
    at execMethod (<my project path>/node_modules/jest-worker/build/workers/processChild.js:128:5)
    at process.messageListener (<my project path>/node_modules/jest-worker/build/workers/processChild.js:46:7)
    at process.emi

Hope this helps others having the same problem!

In my own case I noticed I was using an mp4 video file for my react native application which was too large in size. I had to delete it and that was the fix for me

It took me the whole day but I solved it. I still can't understand why I'm getting this error when I want to launch the app on iOS but:

removing the build directory in android/app fixed it.

To figure out what file caused an error I used @dirk approach. I don't sure why but my App_name.app.dSYM.zip became too large (536MB) so the node was unable to read it because of the 512MB limitation. It might be some different file in your case. Here is a patch-package to get more information about the file which caused this error

diff --git a/node_modules/jest-haste-map/build/worker.js b/node_modules/jest-haste-map/build/worker.js
index 1996d4a..1f17f11 100644
--- a/node_modules/jest-haste-map/build/worker.js
+++ b/node_modules/jest-haste-map/build/worker.js
@@ -146,7 +146,11 @@ function _worker() {
 
     const getContent = () => {
       if (content === undefined) {
-        content = _gracefulFs().default.readFileSync(filePath, 'utf8');
+        try {
+          content = _gracefulFs().default.readFileSync(filePath, 'utf8');
+        } catch (err) {
+          throw new Error(`error readFileSync ${filePath} : ${err.message}`);
+        }
       }
 
       return content;


Make sure you don't have any large files in your root project including (mp4, images, .zip, etc)?

In my case there was a zip file of whole project in the project directory which cause the issue when I remove it from the project directory and run

npm start --reset cache

it worked for me.

Check if there any unrelated file or zip in your project structure/folder if yes then delete file and error will be resolved

Related