当前未启用语法 'nullishCoalescingOperator'

syntax 'nullishCoalescingOperator' isn't currently enabled

当我尝试在 ios-simulator 上构建我的应用程序时,它说:

捆绑失败:语法错误:/Users/MyName/MyApp/node_modules/react-native/node_modules/react-native/Libraries/Components/Switch/Switch.js:当前未启用对实验语法 nullishCoalescingOperator 的支持 (167:52):

 165 |         {...props}
  166 |         {...platformProps}
> 167 |         accessibilityRole={props.accessibilityRole ?? 'button'}
      |                                                    ^
  168 |         onChange={this._handleChange}
  169 |         onResponderTerminationRequest={returnsFalse}
  170 |         onStartShouldSetResponder={returnsTrue}

Add @babel/plugin-proposal-nullish-coalescing-operator (https://git.io/vb4Se) to the 'plugins' section of your Babel config to enable transformation.

我按照上面说的做了,但还是没用... 任何帮助将不胜感激。

我认为通过将 .babelrc 更改为

解决了这个问题
{
  "presets": ["module:metro-react-native-babel-preset"]
}

此更改是由于升级我的 react-native 版本引起的