Importing observer from mobx-react causes "Uncaught TypeError: Super expression must either be null or a function, not undefined"

Importing observer from mobx-react causes "Uncaught TypeError: Super expression must either be null or a function, not undefined"

我正在使用 rails-browserify 和我的 rails 项目来编译 reactJS 应用程序。

我的节点 package.json 文件如下所示:

{
  "dependencies": {
    "babel-core": "^6.13.2",
    "babel-loader": "^6.2.4",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-preset-es2015": "^6.13.2",
    "babel-preset-react": "^6.11.1",
    "babel-preset-stage-1": "^6.13.0",
    "babel-preset-stage-2": "^6.13.0",
    "babelify": "^7.3.0",
    "browserify": "^13.1.0",
    "browserify-incremental": "^3.1.1",
    "mobx": "^2.4.2",
    "mobx-react": "^3.5.4",
    "react": "^15.3.0",
    "react-dom": "^15.3.0",
    "react-router": "^2.6.1",
    "webpack": "^1.13.1"
  }
}

然而,每当我import { observer } from 'mobx-react', 我得到一个

Uncaught TypeError: Super expression must either be null or a function, not undefined

我导入的任何其他库都不会发生这种情况。 reactmobxreact-dom 都可以导入。如果您需要任何其他详细信息,请告诉我。任何帮助表示赞赏。我真的被难住了。

有问题的模块看起来像这样。我还没有在组件中使用 mobx-react,只是导入了它。触发错误的是 import { observer } 行。

import React, { Component } from 'react';
import { observer } from "mobx-react";

export default class OnboardingHeader extends Component {
  constructor(props) {
    super(props);
    this.state = {...}
  }
}

好的,我没有解决这个问题,但我现在想出了一个解决方法。

我将观察者导入移动到两步法中,babelify 似乎更喜欢这样。我变了

import { observer } from 'mobx-react';

import mobxReact from 'mobx-react';
const { observer } = mobxReact;

现在似乎一切正常。问题似乎出在 babelify 以及它如何用库翻译导入。