5

I have initialized a react-native-project and converted it to use TypeScript. I also setup the project to compile to web, android, and ios. Webpack was installed to launch the web version. I got everything working on Web and iOS just fine but when I run yarn android and build to android I get a Syntax error in the Metro window and on the android simulator coming from the index.js file inside the react-native project under node_modules.

This is only happening on Android. I have installed a number of babel plugins and presets so I'm not sure why this index.js file is not working for Android but works correctly on iOS. Any help would be great. I have uploaded the project in a public repo.

I have the starter project available in a github repo so you can pull down my exact setup. https://github.com/hybridmindset/liveapp

I am running on a Mac OS version Catalina 10.15.4 Node v14.0.0

Metro server window with Error

Android Simulator Window with Error

3
  • Did you solve it? I'm having the same problem, but with iOS. Commented Jul 2, 2020 at 15:20
  • Interestingly, I'm also having this problem with the master branch of my project, which builded just fine last week and produced a bundle that is currently in production. That makes me think the problem comes from the state of the tooling, not from its configuration. Commented Jul 3, 2020 at 13:34
  • Re-cloning the rep and setting babel to its defaults solved it for me. Commented Jul 3, 2020 at 14:52

4 Answers 4

2

This might help. Here is my .babelrc: { "presets": [ "@babel/preset-env", "@babel/preset-react", "@babel/preset-flow" ] }

https://github.com/babel/babel/issues/9351

Sign up to request clarification or add additional context in comments.

1 Comment

Look at the babel.config in my repo. I'm already using those presets and it is still not working. My issue looks different than yours. Thanks for commenting tho.
0

If this issue happens to you while upgrading to React Native 0.63 the discussion in this PR might be for you: https://github.com/facebook/react-native/pull/29477

Depending on your situation it might be enough to update your Bundle React Native code and images build phase in Xcode to set this environment variable at the top:

PROJECT_ROOT="$SRCROOT/.."

Alternatively you can apply the changes from mentioned PR using https://github.com/ds300/patch-package.

Comments

0

You might be missing

config{
    ...
    externals : {
        'react': 'React',
        'react-native': true,
    },

in webpack.config.js

Comments

0

I was having the same issue, but the solution of @mukesh fixed for me.

I update my react-native to version 0.67.2 and add @babel/preset-env and @babel/preset-flow to my babel.config.js

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.