babelHelpers.js throws Super expression must either be null or a function, not undefined

时间:2016-06-18 20:03:52

标签: react-native babel

I just updated to RN 0.27 from 0.24 and all these "Super expression must either be null or a function, not undefined" errors started to pop up. After some research I realized there was a breaking change in RN 0.26 so i changed my import statements as indicated in https://github.com/facebook/react-native/releases/tag/v0.25.1 and other StackOverflow posts on the subject. After changing all of my component classes I still see this:

enter image description here

The inherits function in babelHelpers.js is:

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);
}

What is the problem with it? Looks like this is part of react-native library.

I know there is a transform available here to fix the "import problem" in general. Has anyone run it successfully?

BTW - here are my dependencies currently used:

"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"
}

Thank you in advance for your help.

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

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