babel: React Native: Unexpected token ':'. Expected a ')' or a ',' after a parameter declaration.

EDIT by @nicolo-ribaudo: If you see this error in React Native, you probably need to update metro-react-native-babel-preset and run yarn start --reset-cache or npx react-native start --reset-cache - https://github.com/babel/babel/issues/14139#issuecomment-1011836916.


💻

  • Would you like to work on a fix?

How are you using Babel?

babel-loader (webpack)

Input code

devDependencies: {
    "@babel/core": "^7.5.5",
    "@babel/plugin-proposal-class-properties": "^7.0.0",
    "@babel/plugin-transform-runtime": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@babel/preset-flow": "^7.0.0",
    "@babel/preset-react": "^7.0.0",
    "@babel/register": "^7.0.0",
    "@babel/runtime": "^7.5.5",
}

Configuration file name

package.json

Configuration

"babel": {
    "env": {
      "production-web": {
        "presets": [
          "module:metro-react-native-babel-preset",
          "@babel/preset-env",
          "@babel/preset-react",
          "@babel/preset-flow"
        ],
        "plugins": [
          [
            "babel-plugin-react-native-web",
            {
              "commonjs": true
            }
          ],
          "@babel/plugin-proposal-class-properties",
          "@babel/plugin-transform-runtime",
          [
            "extension-resolver",
            {
              "extensions": [
                ".web.js",
                ".js"
              ]
            }
          ]
        ]
      }
    }
  }

Current and expected behavior

Current behavior App shows red box with the error: SyntaxError: Unexpected token ‘:’. Expected a ‘)’ or a ‘,’ after a parameter declaration.

No Stack

Environment

System: OS: macOS 11.4 Binaries: Node: 12.16.1 - ~/Documents/GitHub/unacademy-native/node_modules/.bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.1.0 - ~/Documents/GitHub/unacademy-native/node_modules/.bin/npm npmPackages: @babel/core: ^7.5.5 => 7.16.7 @babel/plugin-proposal-class-properties: ^7.0.0 => 7.16.7 @babel/plugin-transform-runtime: ^7.0.0 => 7.16.8 @babel/polyfill: ^7.0.0 => 7.12.1 @babel/preset-env: ^7.0.0 => 7.16.8 @babel/preset-flow: ^7.0.0 => 7.16.7 @babel/preset-react: ^7.0.0 => 7.16.7 @babel/register: ^7.0.0 => 7.16.9 @babel/runtime: ^7.5.5 => 7.16.7 babel-eslint: ^10.0.2 => 10.1.0 babel-loader: ^8.0.0 => 8.2.3 babel-plugin-extension-resolver: https://github.com/GingerBear/babel-plugin-extension-resolver => 0.0.1 babel-plugin-import: 1.7.0 => 1.7.0 babel-plugin-react-native-web: 0.8.9 => 0.8.9 eslint: ^6.1.0 => 6.8.0 metro-react-native-babel-preset: ^0.56.0 => 0.56.4 react-native: 0.61.4 => 0.61.4 webpack: ^4.6.0 => 4.46.0

Possible solution

Forcing all babel dependecies found in package-lock to a version < 7.16.8

"@babel/core": "7.16.5",
    "@babel/code-frame": "7.16.0",
    "@babel/compat-data": "7.16.4",
    "@babel/generator": "7.16.5",
    "@babel/helper-remap-async-to-generator": "7.16.5",
    "@babel/plugin-proposal-class-properties": "7.16.5",
    "@babel/plugin-transform-runtime": "7.16.5",
    "@babel/helper-wrap-function": "7.16.5",
    "@babel/parser": "7.16.6",
    "@babel/runtime-corejs3": "7.16.5",
    "@babel/traverse": "7.16.5",
    "@babel/types": "7.16.0",
    "@babel/plugin-proposal-async-generator-functions": "7.16.5",
    "@babel/plugin-transform-async-to-generator": "7.16.5",
    "@babel/plugin-transform-modules-commonjs": "7.16.5",
    "@babel/plugin-transform-named-capturing-groups-regex": "7.16.5",
    "@babel/plugin-transform-typescript": "7.16.1",
    "@babel/preset-env": "7.16.5",
    "@babel/preset-flow": "7.16.5",
    "@babel/preset-react": "7.16.5",
    "@babel/register": "7.16.5",
    "@babel/runtime": "7.16.5",

Additional context

This started happening since 7.16.8 was release.

Screenshot 2022-01-12 at 1 50 25 PM

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 52 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I have the same problem. This is caused by #14105.

Because of https://github.com/facebook/metro/blob/v0.58.0/packages/metro-react-native-babel-preset/src/transforms/transform-symbol-member.js#L52 will transform Symbol.iterator, but the change of #14105 will cause transform is break, finally the rest flow grammar is reserved.

Please update metro-react-native-babel-preset from 0.58.0 to 0.59.0 to resolve it.

If it doesn’t take effect, please try yarn start --reset-cache to restart app.

And other two solutions: (only use one of)

from:

    module.exports = {
       presets: ['module:metro-react-native-babel-preset'],
    };

to:

    module.exports = {
       presets: [['module:metro-react-native-babel-preset', {
            unstable_disableES6Transforms: true
        }]],
    };

finally run yarn start --reset-cache to restart app.

@Rekha16 @leandrovidal56 @qianqiang2017 Please read #14139 (comment) again to try other solutions.

thank you @kerm1it, I find possible solution, it’s good for me depends your machine you need use this command

  • npx react-native start --reset-cache

I have the same problem. This is caused by #14105.

Because of https://github.com/facebook/metro/blob/v0.58.0/packages/metro-react-native-babel-preset/src/transforms/transform-symbol-member.js#L52 will transform Symbol.iterator, but the change of #14105 will cause transform is break, finally the rest flow grammar is reserved.

Please update metro-react-native-babel-preset from 0.58.0 to 0.59.0 to resolve it.

If it doesn’t take effect, please try yarn start --reset-cache to restart app.

And other two solutions: (only use one of)

from:

    module.exports = {
       presets: ['module:metro-react-native-babel-preset'],
    };

to:

    module.exports = {
       presets: [['module:metro-react-native-babel-preset', {
            unstable_disableES6Transforms: true
        }]],
    };

finally run yarn start --reset-cache to restart app.

Thanks guy, it work

I have some problem React Native 0.61.5

#14139 These steps worked for me-

  1. In cmd echo $TMPDIR
  2. Go to path and remove metro-cache (rm -r metro-cache)
  3. remove node modules, package-lock
  4. npm cache clean --force
  5. upgrade metro-react-native-babel-preset version to 0.59.0
  6. npm install
  7. npm start – --reset-cache

Guys, thank you all so much for helping to resolve the problem. This is what helped me:

  1. I deleted node_modules
  2. I added to package.json
 "devDependencies": {
    "@babel/core": "7.16.7",
    "@babel/preset-flow": "7.16.7",
    "@babel/runtime": "7.16.7",
    "@babel/traverse": "7.16.7",
    "metro-react-native-babel-preset": "^0.59.0",
 },
 "resolutions": {
    "@babel/traverse": "7.16.7"
  },
  1. I added to babel.config.js
module.exports = {
  presets: [[
    'module:metro-react-native-babel-preset',
    {
      unstable_disableES6Transforms: true
    }
]],
};
  1. I run npm i --legacy-peer-deps
  2. cd android && gradlew clean
  3. cd ..
  4. react-native run-android
  5. react-native start --reset-cache

I hope it will help those who still trying to make it work. Take care and thanks again for all the previous answers.

Guys, thank you all so much for helping to resolve the problem. This is what helped me:

  1. I deleted node_modules
  2. I added it to package.json
 "devDependencies": {
    "@babel/core": "7.16.7",
    "@babel/preset-flow": "7.16.7",
    "@babel/runtime": "7.16.7",
    "@babel/traverse": "7.16.7",
    "metro-react-native-babel-preset": "^0.59.0",
 },
 "resolutions": {
    "@babel/traverse": "7.16.7"
  },
  1. I added to babel.config.js
module.exports = {
  presets: [[
    'module:metro-react-native-babel-preset',
    {
      unstable_disableES6Transforms: true
    }
]],
};
  1. I run npm i --legacy-peer-deps
  2. cd android && gradlew clean
  3. cd ..
  4. react-native run-android
  5. react-native start --reset-cache

I hope it will help those who still trying to make it work. Take care and thanks again for all the previous answers.

hey thank you so much, it works …

I have the same problem. This is caused by #14105.

Because of https://github.com/facebook/metro/blob/v0.58.0/packages/metro-react-native-babel-preset/src/transforms/transform-symbol-member.js#L52 will transform Symbol.iterator, but the change of #14105 will cause transform is break, finally the rest flow grammar is reserved.

Please update metro-react-native-babel-preset from 0.58.0 to 0.59.0 to resolve it.

If it doesn’t take effect, please try yarn start --reset-cache to restart app.

And other two solutions: (only use one of)

from:

    module.exports = {
       presets: ['module:metro-react-native-babel-preset'],
    };

to:

    module.exports = {
       presets: [['module:metro-react-native-babel-preset', {
            unstable_disableES6Transforms: true
        }]],
    };

finally run yarn start --reset-cache to restart app.

Working for me.

Oh thanks @kerm1it for investigating! We have some e2e tests to verify that we don’t break React Native support, but we are only testing recent versions and metro-react-native-babel-preset 0.58.0 is two years old 😅

Since #14105 is a fix for an actual bug, and the metro-react-native-babel-preset code you linked is clearly wrong (it asks Babel to stop the whole traversal with path.stop(), rather than just to avoid recursing in the current node with path.skip()), I’m tempted to leave the situation as-is.

I will pin this issue for now, so that if anyone has the same problem they will see your suggested solution (i.e. update metro-react-native-babel-preset). Thank you!

Update babel-preset-expo to 8.3.0 or a newer version. Then you might need to clear expo’s cache, if it has one.

Thank you So much. it helped me out. my error is gone.

I updated: "babel-preset-expo": "~8.1.0" to "babel-preset-expo": "~8.3.0" then run: expo start -c

everything come back to life Happy coding!🙌🏻✌🏻

Update babel-preset-expo to 8.3.0 or a newer version. Then you might need to clear expo’s cache, if it has one.

for those having this issue, simple adding “babel-preset-expo”: “~8.3.0” alone to my project fixed this error. “@babel/core”: “^7.8.6”, is all i had.

npx react-native start --reset-cache this command fixed my issue thanks guys

@rishabh876 sure, here it is

module.exports = { presets: [[ 'module:metro-react-native-babel-preset', { unstable_disableES6Transforms: true } ]] };

This is the babel.config.js file stored at node_modules/react-native/template/babel.config.js

@Rekha16 @leandrovidal56 @qianqiang2017 Please read #14139 (comment) again to try other solutions.

thank you @kerm1it, but I don’t have success yet

image image image image image

I guess it is caused by cache (ensure you restart app with yarn start --reset-cache and https://github.com/babel/babel/issues/14139#issuecomment-1011836916 these solutions you only use one of them,don’t use mix up with them )