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.

About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 52 (5 by maintainers)
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
from0.58.0
to0.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)
resolutions
ofyarn
to lock@babel/traverse
to7.16.7
(https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/#toc-how-to-use-it) and runyarn
to reinstall, finally runyarn start --reset-cache
to restart app.babel.config.js
of your project : (assume yourmetro-react-native-babel-preset
is0.58.0
)from:
to:
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-
Guys, thank you all so much for helping to resolve the problem. This is what helped me:
npm i --legacy-peer-deps
cd android && gradlew clean
cd ..
react-native run-android
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 …
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 withpath.stop()
, rather than just to avoid recursing in the current node withpath.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!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
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 )