Najib Fadil
Najib Fadil

Reputation: 923

compiling js failed react native expected buffer size

My code was working fine and then suddenly start showing error something like this:-

Compiling JS failed: 180820:25:';' expected Buffer size 7070676 starts with:....... and has protection mode(s): r--p

Error Screenshot
Error Screenshot

I tried resetting the cache with

npx react-native start --reset-cache

I am using the latest version of every module in my code the last change is to remove the "AsyncStorage" module.

Upvotes: 27

Views: 36888

Answers (16)

ISRAR KHAN
ISRAR KHAN

Reputation: 1

I faced the same issue due to a syntax problem in the used translation json files of I18N module. just missing semicolon in this file. Just fixing the syntax problem of translation files resolved the problem.

Upvotes: 0

Pika Meth
Pika Meth

Reputation: 19

Experienced the same issue, not using any async functions nor updated any of the modules

I restarted the app, rerun prebuild, restarting the emulator and none of these worked. What worked for me was terminating node because it was hogging 1GB of ram for some reason then restarted the app and it worked again

Upvotes: 0

Bruno Pintos
Bruno Pintos

Reputation: 481

In my case, I didn't have the metro running. react-native start and reloading the app solved it for me.

Upvotes: 0

Archit Garg
Archit Garg

Reputation: 1

The fix: check babel.config.js

I was having exact same issue since I implemented react-native-web in my existing react-native application, when I debugged by reverting to old commits and applying the changes file by file, I found out that it was because of some babel plugins/presets [which were not even required in the native build] So for a fix, I created separate config files babel.config.native.js and babel.config.web.js, and don't forget to update the import in the webpack.config.js for babel to babel.config.web.js [If you have a webpack file]

Upvotes: 0

Muhammad Umar
Muhammad Umar

Reputation: 229

I was also facing this issue, and I wasn't using any async function.

I simply uninstalled the app and rebuilt it, and the app started working.

Upvotes: 2

Arun Y
Arun Y

Reputation: 21

After spending two days attempting various solutions, including clearing the cache, restarting, creating a new emulator, validating asynchronous operations without synchronization, and checking JSON files for errors, none of them resolved the issue.

Ultimately, clearing the temporary files on Windows using '%Temp%' proved to be the solution, and it started working.

Upvotes: 2

Umanda
Umanda

Reputation: 4843

I encountered a similar issue in my development setup. To resolve it, I completely removed my existing virtual device and then set up a new one from scratch. This process effectively addressed the problem within my Android development environment on a Windows 11 system.

Here are the steps I followed for anyone facing a similar issue

  1. Open the Android Virtual Device (AVD) Manager in your Android development environment.

  2. Select the problematic virtual device and click on the "Delete" option to remove it.

  3. After successfully deleting the old virtual device, click on the "Create Virtual Device" button to initiate the setup of a new device.

  4. Follow the on-screen instructions to configure your new virtual device according to your development needs.

This method worked for me and might be beneficial for others experiencing similar issues."

Upvotes: 0

Estiven Laferre
Estiven Laferre

Reputation: 86

try npm cache clean --force or yarn cache clean

Upvotes: 3

Chamile Balasuriya
Chamile Balasuriya

Reputation: 131

Having the exact same issue, using typescript react native, get this issue when runs the application in android emulator, problem happens when creating the axios instance inside of service.ts file.

[Error: Exception in HostFunction: Compiling JS failed: 4:3:export declaration must be at top level of module Buffer size 1287 starts with: 5f5f642866756e6374696f6e2028676c]

import axios from "axios"

var instance = axios.create

"axios": "1.1.0",
"react": "18.2.0",
"react-native": "0.73.1",

enter image description here

Upvotes: 1

Mohamed Belhassen
Mohamed Belhassen

Reputation: 33

I faced the same issue due to a syntax problem in the used translation json files of I18N module. Just fixing the syntax problem of translation files resolved the probem.

Upvotes: 0

dilna mohandas
dilna mohandas

Reputation: 21

I experienced the same issue due to a missing Quotation mark ("), just run react-native bundle command and it will show you the error line

react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res

Upvotes: 2

hmlasnk
hmlasnk

Reputation: 1322

I experienced the same issue due to a missing curly bracket in one of my translation (localization) files. Resolving this by fixing the file resolved the issue.

Upvotes: 16

tuliomir
tuliomir

Reputation: 416

I'll just emphasize the comment @Lukas Hechenberger made on the selected answer: "You can view your bundle at localhost:8081/…. - Copy-Paste it to an IDE and you'll see what went wrong".

This link was a life saver, as it indicates clearly at which line the problem happened - be it an invalid JSON or a misplaced await.

The link is:

http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true

replacing the platform part with your needs, ios or android.

Upvotes: 14

Sajad Speed
Sajad Speed

Reputation: 573

I also had this problem until I realized that I had imported and used a json file, but it was empty.

Upvotes: 2

Eduardo Ramos
Eduardo Ramos

Reputation: 534

find . -name "*.json" -not -path "./node_modules/*" -print0 | while IFS= read -d '' -r filename; do
    if ! jq . "$filename" >/dev/null 2>&1; then
        echo "$filename is invalid"
    fi
done

This bash script may help to find some .json files malformed. Which leads to this crash.

Upvotes: 5

Najib Fadil
Najib Fadil

Reputation: 923

After reviewing the change I made, it seems that I used and await call outside an async function, and that's what caused this error.

Upvotes: 54

Related Questions