Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RN project fails with "Property body[6] of BlockStatement..." (Babel related issue) #31960

Closed
wdamien opened this issue Aug 4, 2021 · 48 comments
Labels
Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. JavaScript Resolution: Fixed A PR that fixes this issue has been merged. Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.

Comments

@wdamien
Copy link

wdamien commented Aug 4, 2021

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
@pulnec

This comment has been minimized.

@enrickpb
Copy link

enrickpb commented Aug 5, 2021

Same here

1 similar comment
@amadeuszblanik
Copy link

Same here

@douglowder

This comment has been minimized.

@GiordanoSpiropulos

This comment has been minimized.

@vkkostin

This comment has been minimized.

@nucks

This comment has been minimized.

@amadeuszblanik

This comment has been minimized.

@pulnec

This comment has been minimized.

@GiordanoSpiropulos

This comment has been minimized.

@douglowder

This comment has been minimized.

@nucks

This comment has been minimized.

@douglowder

This comment has been minimized.

@GiordanoSpiropulos

This comment has been minimized.

@punreachrany

This comment has been minimized.

@pulnec

This comment has been minimized.

@nucks

This comment has been minimized.

@pulnec

This comment has been minimized.

@lslsls0001

This comment has been minimized.

@nucks

This comment has been minimized.

@lslsls0001

This comment has been minimized.

@lslsls0001

This comment has been minimized.

@lslsls0001

This comment has been minimized.

@pulnec

This comment has been minimized.

@nucks

This comment has been minimized.

@catnofish93

This comment has been minimized.

@Revolt9k
Copy link

Revolt9k commented Aug 5, 2021

Released in @babel/plugin-transform-react-display-name@7.15.1: https://www.npmjs.com/package/@babel/plugin-transform-react-display-name/v/7.15.1

Still facing the same issue, updating plugin to 7.15.1 doesnt help.
Dont sure you can reproduce it on linux, you needs Mac to make a build on Xcode to reproduce the issue.

@kelset kelset changed the title Compiling a new project using typescript fails Creating a new app with npx react-native init exit with error (Babel related issue) Aug 5, 2021
@kelset kelset added Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. JavaScript and removed Needs: Triage 🔍 labels Aug 5, 2021
@kelset kelset pinned this issue Aug 5, 2021
@kelset kelset changed the title Creating a new app with npx react-native init exit with error (Babel related issue) RN project fails with "Property body[6] of BlockStatement..." (Babel related issue) Aug 5, 2021
@nicolo-ribaudo
Copy link

@Revolt9k Can you share your lockfile?

@Revolt9k
Copy link

Revolt9k commented Aug 5, 2021

@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

@kelset
Copy link
Contributor

kelset commented Aug 5, 2021

@Revolt9k me and @nicolo-ribaudo have just done a pairing session to verify that @babel/plugin-transform-react-display-name version 7.15.1 works correctly.

So, to more completely provide a resolution if you are still experiencing the problem:

  1. check your yarn/npm lock file. Remove the lines/section about
"@babel/plugin-transform-react-display-name@^7.0.0":
  version "7.15.0"
  // more lines
  1. (optional) remove your node_modules folder
  2. do a yarn/npm install. Afterwards, check the yarn / npm lock file. You should see something like this in place:
"@babel/plugin-transform-react-display-name@^7.0.0":
  version "7.15.1" <--- THIS IS THE VERSION YOU NEED TO HAVE
  resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-display-name/-/plugin-transform-react-display-name-7.15.1.tgz#6aaac6099f1fcf6589d35ae6be1b6e10c8c602b9"
  integrity sha512-yQZ/i/pUCJAHI/LbtZr413S3VT26qNrEm0M5RRxQJA947/YNYwbZbBaXGDrq6CG5QsZycI1VIP6d7pQaBfP+8Q==
  dependencies:
    "@babel/helper-plugin-utils" "^7.14.5"
  1. Now, reset the reset your Metro cache; you can do it in a few ways, the one I use the most is to kill off the running instance, and re-start it via yarn start --reset-cache. You can also do a more complete nuke via rm -rf $TMPDIR/metro-*.

Doing so will ensure that Metro will pick up the correct plugin and things should work again for you too :)

@sammy-SC
Copy link
Contributor

sammy-SC commented Aug 5, 2021

We'll try to reland this change making sure that it doesn't break. I never used React Native: is there an example app or a command I can run on Linux to reproduce the error?

@nicolo-ribaudo you can follow https://reactnative.dev/docs/environment-setup to create and build a project. If the error happens on Android, you should be able to repro on Linux as well. If it happens on iOS only, you will need MacOS.

@kelset
Copy link
Contributor

kelset commented Aug 5, 2021

@sammy-SC yeah the error happens at the Metro step so the Babel team should be even able to get a "small footprint" CI setup for their workflow that is able to catch these kind of issues in the future: babel/babel#13639

@kelset kelset added Resolution: Fixed A PR that fixes this issue has been merged. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. labels Aug 5, 2021
@Revolt9k
Copy link

Revolt9k commented Aug 5, 2021

Thank you guys, reseting Metro cache finally fixes the issue. You are amazing <3.

@SaeedPoureshghi
Copy link

I have still problem.
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"

@NicolasFelippe
Copy link

Thanks for this solution, for people who still have the problem, make sure you are following the step by step of the friend from above.

@kelset

@vmarcel
Copy link

vmarcel commented Aug 5, 2021

After applying the fix I get a new issue.

error: index.js: .env["development"].plugins[0][1] must be an object, false, or undefined

Should I just scrap it and create a new project?

@PedRonald
Copy link

resolvi segue a solução:

digita dentro do seu projeto:

npm update @babel/plugin-transform-react-display-name

após finalizar a atualização, so dar npx react-native run-android e seja feliz

@safaiyeh
Copy link
Contributor

Closing as the team got a resolution for this.

@kelset kelset unpinned this issue Sep 30, 2021
@facebook facebook locked as resolved and limited conversation to collaborators Aug 16, 2022
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. JavaScript Resolution: Fixed A PR that fixes this issue has been merged. Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.
Projects
None yet
Development

No branches or pull requests