【问题标题】:babelHelpers.js throws Super expression must either be null or a function, not undefinedbabelHelpers.js 抛出 Super 表达式必须为 null 或函数,而不是未定义
【发布时间】:2016-06-18 20:03:52
【问题描述】:

我刚刚从 0.24 更新到 RN 0.27,所有这些“超级表达式必须为空或函数,而不是未定义”错误开始弹出。经过一些研究后,我意识到 RN 0.26 发生了重大变化,因此我更改了我的导入语句,如 https://github.com/facebook/react-native/releases/tag/v0.25.1 以及有关该主题的其他 StackOverflow 帖子。更改所有组件类后,我仍然看到:

babelHelpers.js 中的继承函数是:

babelHelpers.inherits = function (subClass, superClass) {
    if (typeof superClass !== "function" && superClass !== null) {
    throw new TypeError("Super expression must either be null or a function,not " + typeof superClass);
}

它有什么问题?看起来这是 react-native 库的一部分。

我知道有一个可用的转换here 来解决一般的“导入问题”。有人成功运行了吗?

顺便说一句 - 这是我当前使用的依赖项:

"dependencies": {
  "@remobile/react-native-splashscreen": "^1.0.3",
  "babel-polyfill": "^6.9.1",
  "react": "^15.1.0",
  "react-native": "^0.27.2",
  "react-native-navbar": "^1.5.0",
  "react-native-side-menu": "^0.18.1",
  "realm": "^0.13.2"
},
"devDependencies": {
  "babel-jest": "^12.1.0",
  "babel-polyfill": "^6.9.1",
  "jest-cli": "^12.1.1",
  "react-addons-test-utils": "^15.1.0"
}

提前感谢您的帮助。

【问题讨论】:

    标签: react-native babeljs


    【解决方案1】:

    原来问题出在其中一个附加包上。当我查看堆栈时,有一个类 monthSelector.js 的引用,其中第 20 行有对 react-native-side-menu 附加包的引用。 当我查看他们的 index.js 时——果然是从 react-native 导入 Component 而不是 react。 他们的新版本 0.19 修复了这个问题。

    【讨论】:

      【解决方案2】:

      我的问题是,在index.android.js 中,我使用了一个组件类来派生AndroidApp,而AndroidApp 不存在(不再存在)。该错误是传递给babelHelpers.inherits()superClass 参数为undefined 的结果。

      错误消息并没有那么有用,因为inherits() 函数只检查superClass 是否不为空。如果它也检查undefined,那就太好了。

      【讨论】:

        猜你喜欢
        • 2015-12-30
        • 2017-05-11
        • 2016-10-07
        • 1970-01-01
        • 2018-02-19
        • 2017-07-11
        • 2018-01-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多