react-native: [android / ios] bundling failed: "TransformError

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

  1. react-native -v: react-native-cli: 2.0.0 react-native: n/a - not inside a React Native project directory (I was inside the folder, version is: 0.47.1)
  2. node -v: v7.10.0
  3. npm -v: 4.2.0
  4. yarn --version: 0.17.10

Then, specify:

  • Target Platform: Android, iOS
  • Development Operating System: macOS Sierra 10.12.6
  • Build tools: Using Xcode 8.3.3 and Android Studio 2.3

Steps to Reproduce

  1. react-native init rn_reproduce_transform_error
  2. cd rn_reproduce_transform_error
  3. react-native run-ios or react-native run-android

Expected Behavior

Should show the default “Welcome to React Native!” screen.

Actual Behavior

bundling failed: "TransformError: /Users/eduardo/Desktop/rn_reproduce_transform_error/index.ios.js: Unexpected token ) (While processing preset: /Users/eduardo/Desktop/rn_reproduce_transform_error/node_modules/babel-preset-react-native/index.js)"

Same error occurs when I tried to update RN version to 0.48.0-rc.1 SyntaxError: Unexpected token )

Reproducible Demo

https://github.com/esganzerla/rn_reproduce_transform_error

Notes

  • This happens both on android and iOS.
  • I saw some people having the same problem on issue #15496.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 42
  • Comments: 35 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve just found a workaround:

yarn remove babel-preset-react-native yarn add babel-preset-react-native@2.1.0

The hole is probably deeper, but that is works for me.

It is a bug an the work around that worked for me was to edit dependency of babel in package.json to “babel-preset-react-native”: “2.1.0”. After which I deleted node_modules and re-installed the npm (npm install). Then it worked like a charm.

If you Still Getting Problem in babel-preset-react-native then try Following Process

package.json

“dependencies”: { “react”: “16.0.0-alpha.12”, “react-native”: “0.47.1”, “babel-preset-react-native”: “2.1.0” --------->Here },

Delete ‘Node_modules’ folder from react native project manually and run followinf Commands in react native project $ npm install $ npm start – --reset-cache $ react-native run-android

Restarting didn’t help here too.

@tmartres Restarting don’t work for me

@Ibrokola thanks worked for me.

  1. delete node_modules folder
  2. go to package.json and change babel-preset-react-native: 3.0.0" to babel-preset-react-native: 2.1.0"
  3. run “npm install”

Check index.ios.js, see if there is a trailling comma. If so, delete it. It works for me.

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  // ↑ here, delete it
});

for my case , it need execute npm install babel-preset-react-native@2.1.0 --save-dev , it works for me .

Thx a lot dude @esganzerla , your workaround fixed my problem

Thank you for reporting and for the workaround @esganzerla.

It seems an issue with babel-preset-react-native@3.0.0 that was released earlier.

@jeanlauliac How should we fix this issue? Add a specific major version in react-native-cli? Or something has been planned? https://github.com/facebook/react-native/blob/a54d449e947afc609a404a699494902823fbbf5e/local-cli/init/init.js#L91

cc @ericnakagawa who’s on call.

I’m running into this in babel-preset-react-native: ^5.0.0. Anyone else having this problem? I’ve tried several different versions of babel-preset-react-native and haven’t had any luck. Been debugging it for 7-8 hours now. Clearing xcode caches, npm caches, deleting and reinstalling pods, node modules, restarting process on :8081, where else could this be coming from? …

error: bundling failed: SyntaxError: /nikkwong/index.js: Unexpected token < (19:12)
  17 |     render() {
  18 |         return (
> 19 |             <View>Hi</View>
     |             ^
  20 |         )
  21 |     }
  22 | }

@cheng-kang your answer worked. I did all the steps necessary, yarn delete yarn add, npm install, uninstall, babel preset version upgrades but nothing worked but your solution.

@ShubhamBabhulkar, I think there’s a bug 🐜 in 3.0 that needs to be fixed…

On Fri, Aug 18, 2017 at 1:34 AM ShubhamBabhulkar notifications@github.com wrote:

Nice @Ibrokola https://github.com/ibrokola, But we need to do same thing every time?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/facebook/react-native/issues/15513#issuecomment-323282082, or mute the thread https://github.com/notifications/unsubscribe-auth/ALDc79xluQWLtQPHtA5VDmM3fFtHIR3xks5sZT58gaJpZM4O5FBE .

Did you delete node_modules if not delete node_modules and run npm install. I am certain it will work.

On Thu, Aug 17, 2017 at 4:02 AM, ShubhamBabhulkar notifications@github.com wrote:

npm add babel-preset-react-native@2.1.0 Command not Work, please give me any Solution

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/facebook/react-native/issues/15513#issuecomment-323025130, or mute the thread https://github.com/notifications/unsubscribe-auth/ALDc7zu166CVKRCKtLVtZaoWhWTWxOQyks5sZA-jgaJpZM4O5FBE .

uninstalling and installing babel-preset-react-native works for me thanks a lot @esganzerla

I’ve tried to create a new RN app by RNCA (Expo) and then eject it. Works perfectly fine, although it runs on React Native 0.46.1, so I’m guessing this is an issue with 0.47.