react-native: RN project fails with "Property body[6] of BlockStatement..." (Babel related issue)
EDIT by @kelset: this is caused by a Babel release, read more at this comment. The offending commit has been reverted, as mentioned here - so the issue is solved now. If you are still experiencing it, follow the steps described here.
PLEASE don’t post comments like “same here”, they only create noise
When creating a new project via npx react-native init Foo --template react-native-template-typescript
, then running the default yarn ios
metro throws a compile error:
error: node_modules/react-native/Libraries/Image/ImageAnalyticsTagContext.js: Property body[6] of BlockStatement expected node to be of a type ["Statement"] but instead got "AssignmentExpression"
Tested using:
- Typescript 3.9.4 and 4.3.5
- React Native: 0.64.1
- macOS 11.4
- node v14.15.1
- yarn 1.22.10
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 48 (5 by maintainers)
this is a known issue caused by a bug in a newly released version of babel. it will impact all new react-native and expo apps. you can resolve it with yarn resolutions in a new project:
see some discussion here:
@Revolt9k me and @nicolo-ribaudo have just done a pairing session to verify that
@babel/plugin-transform-react-display-name
version7.15.1
works correctly.So, to more completely provide a resolution if you are still experiencing the problem:
yarn start --reset-cache
. You can also do a more complete nuke viarm -rf $TMPDIR/metro-*
.Doing so will ensure that Metro will pick up the correct plugin and things should work again for you too 😃
This error started to come out today too.
We are sorry for this, I’m reverting the change at https://github.com/babel/babel/pull/13637.
you can also remove the current @babel/core from the package.json and install this version
npm install --save-dev @babel/ core@7.12.9
Same for us, started about three hours ago.
this are my dependencies
"@babel/core": "7.14.6", "@babel/runtime": "7.14.6"
@pulnec how is that working?
@babel/runtime
version7.12.9
does not exist.Apparently it may be a problem with the babel, copy the folder ‘@babel’ that is in the node_modules of a working project, in the new project and it ran without problems.
it may be due to an update they did a couple of hours ago
Thank you guys, reseting Metro cache finally fixes the issue. You are amazing ❤️.
@nicolo-ribaudo Lockfile is too long to put it here, so I had to upload it in readme file in empty repository. You can check it there - https://github.com/Revolt9k/lockfile
@douglowder @babel/core