Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property body[41] of BlockStatement expected node to be of a type ["Statement"] but instead got "AssignmentExpression"

My react native project worked fine yesterday. But this morning, after I tried to run it again, it gave me the following error:

error node_modules/react-native/Libraries/Components/ScrollView/ScrollView.js: Property body[41] of BlockStatement expected node to be of a type ["Statement"] but instead got "AssignmentExpression". Run CLI with --verbose flag for more details.
TypeError: Property body[41] of BlockStatement expected node to be of a type ["Statement"] but instead got "AssignmentExpression"

I'm not sure what it means, though. How can I solve this issue?

like image 634
Time Flies Avatar asked Aug 05 '21 01:08

Time Flies


4 Answers

This appears to be a bug with 7.15.0 of Babel which they are making a E2E React native regression test for.

Updated answer

A few hours ago they have released the fix. It is due to a change to @babel/plugin-transform-react-display-name which has been reverted in 7.15.1. With that fix, you should be able to remove the extra entries in the package.json from my original answer and instead do the following.

npm install --save-dev @babel/core@latest

Original answer

Unfortunately, simply downgrading @babel/core to 7.14 will not be enough because it seems to pull the latest dependencies for the other components. Instead what you need to do is lock down @babel/core and any other Babel component you are working that is coercing @babel/types to go to 7.15.0

Here's the relevant section I had in my package.json

"@babel/core": "~7.14.0",
"@babel/compat-data": "~7.14.0",
"@babel/generator": "~7.14.0",
"@babel/helper-compilation-targets": "~7.14.0",
"@babel/helper-create-class-features-plugin": "~7.14.0",
"@babel/helper-create-regexp-features-plugin": "~7.14.0",
"@babel/helper-member-expression-to-functions": "~7.14.0",
"@babel/helper-module-transforms": "~7.14.0",
"@babel/helper-replace-supers": "~7.14.0",
"@babel/plugin-transform-react-display-name": "~7.14.0",
"@babel/plugin-transform-runtime": "~7.14.0",
"@babel/types": "~7.14.0",

Just replace all of that and perform an npm install and let it try to resolve and test your scenario again. If it still fails just look at package-lock.json and locate 7.15.0 and adjust the dependency accordingly

With this approach you don't need to "recover" from a zip file.

like image 118
Archimedes Trajano Avatar answered Oct 10 '22 16:10

Archimedes Trajano


Apparently, it may be a problem with the babel. Copy the folder @babel (specifically @babel/core) that is in the node_modules of a working project into the new project and it runs without problems.

It may be due to an update they did a couple of hours ago.

You can also remove the current @babel/core from the package.json and install this version npm install --save-dev @babel/core@latest.

Or use this:
@babel file: https://drive.google.com/file/d/1-z_4H_z4x075unZqZD41WYUwY_hsrKox/view.

Or replace the following codes in your package.json file then npm install.

"@babel/core": "~7.14.0",
"@babel/compat-data": "~7.14.0",
"@babel/generator": "~7.14.0",
"@babel/helper-compilation-targets": "~7.14.0",
"@babel/helper-create-class-features-plugin": "~7.14.0",
"@babel/helper-create-regexp-features-plugin": "~7.14.0",
"@babel/helper-member-expression-to-functions": "~7.14.0",
"@babel/helper-module-transforms": "~7.14.0",
"@babel/helper-replace-supers": "~7.14.0",
"@babel/plugin-transform-react-display-name": "~7.14.0",
"@babel/plugin-transform-runtime": "~7.14.0",
"@babel/types": "~7.14.0",
like image 27
Time Flies Avatar answered Oct 10 '22 17:10

Time Flies


the problem is due to a babel update that affected the RN project. copy @babel from some other project and paste in node_modules or Download the @babel folder from here and replace the existing folder in the node_modules.Babel Download

And run

npm start --reset-cache
like image 3
Emmanuel Oreoluwa Avatar answered Oct 10 '22 16:10

Emmanuel Oreoluwa


I've had this come up when I change git branches and need to do a yarn install. I like the comment to change the bable version since I'm also on 7.15 and I'll try this the next time it occurs...

To get around this I have successfully:

  1. Stopped metro
  2. ran a cleanup script (included below)
  3. removed/uninstall app from device/simulator
  4. started metro
  5. installed app
  6. sometimes I still get the error and do 1-5 again and it works.

my cleanup script

#!/bin/bash

echo "clean'n android"
cd ./android && ./gradlew clean
cd ..

rm -rf ./node_modules
yarn cache clean
rm ./yarn.lock

rm -rf $TMPDIR/react-*
rm -rf $TMPDIR/metro-builder-cache-*

yarn install

like image 3
Robel Robel Lingstuyl Avatar answered Oct 10 '22 17:10

Robel Robel Lingstuyl