React Native:错误“意外的标识符‘_classCallCheck’。导入调用需要一个参数”

Dou*_*XXX 12 android react-native

我在我的android程序上使用React-Native,在打开我的项目后react-native run-android,发生了错误。同样的错误消息出现了两次。

Unexpected identifier '_classCallCheck'.import call expects exactly one argument

Unexpected identifier '_classCallCheck'.import call expects exactly one argument

no stack

no stack
Run Code Online (Sandbox Code Playgroud)

我用谷歌搜索并尝试了一些解决方案,但仍然无法解决。这是我发现的类似问题: https ://github.com/facebook/react-native/issues/23669

对于这个错误我已经尝试过:

  1. cd 到 /andorid,使用gradlew clean
  2. 使用react-native start --reset-cache
  3. 使用npm install -g react-native-cli

这是我的开发环境:

Android: 
AVD version: Android 7.0 with Play Store    
System:
OS: Windows 10 10.0.19043
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory: 2.11 GB / 15.71 GB
Binaries:
Node: 10.16.0 - D:\nodejs\node.EXE
Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
npm: 6.9.0 - D:\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK:
  API Levels: 28, 32
  Build Tools: 28.0.3, 32.0.0
  System Images: android-24 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom
  Android NDK: Not Found
Windows SDK: Not Found
IDEs:
Android Studio: Version     2020.3.0.0 AI-203.7717.56.2031.7935034
Visual Studio: Not Found
Languages:
Java: 1.8.0_232
npmPackages:
@react-native-community/cli: Not Found
react: 16.9.0 => 16.9.0
react-native: ^0.64.0 => 0.64.3
react-native-windows: Not Found
npmGlobalPackages:
*react-native*: Not Found
Run Code Online (Sandbox Code Playgroud)

伙计们,我刚刚解决了这个问题。这是链接。 https://github.com/babel/babel/issues/14139

从:

module.exports = {
   presets: ['module:metro-react-native-babel-preset'],
};
Run Code Online (Sandbox Code Playgroud)

到:

module.exports = {
   presets: [['module:metro-react-native-babel-preset', {
        unstable_disableES6Transforms: true
    }]],
};
Run Code Online (Sandbox Code Playgroud)

小智 6

我遇到了同样的问题,上面的步骤不起作用,所以我将 Metro-react-native-babel-preset 从 0.56.0 更新到 0.59.0 并且它起作用了。


leo*_*ooo 0

1.在您的终端中输入:

npm ls metro-config
Run Code Online (Sandbox Code Playgroud)

你会看到你的react-native版本需要metro-config版本

  1. 更改这些依赖项的版本:
    "metro": "^0.59.0",
    "metro-core": "^0.59.0",
    "metro-react-native-babel-preset": "^0.59.0",
Run Code Online (Sandbox Code Playgroud)
  1. 清晰的守望者手表:守望者 watch-del-all
  2. 删除node_modules并运行yarn install
  3. 通过传递 --reset-cache 标志或添加来重置 Metro 的缓存
  4. ResetCache:对于您的 Metro 配置文件来说是正确的。
  5. 删除缓存: rm -rf ${TMPDIR:-/tmp}/metro-*
  6. 如果需要添加
      resetCache: true,
Run Code Online (Sandbox Code Playgroud)

在你的 Metro.config.js 中