编译Babel时的类型错误class.default不是构造函数


'use strict';
/**
* PortalHTML.js
*/
import SingleContextHTML from './SingleContextHTML';
import MultiContextHTML from './MultiContextHTML';
export default class PortalHTML{
    constructor (type) {
          switch(type) {
        case "1":
          this.portalStrategy = new SingleContextHTML();
          break;
        default:
          this.portalStrategy = new MultiContextHTML();
          break;
           }
    }
    render (...args) {
        this.portalStrategy.renderHTML(args);
    }
    _strategyPeak(){
        return this.portalStrategy.constructor.name;
    }
}
/**
* SingleContextHTML.js
*/
'use strict';
import PortalHTMLStrategy from './PortalHTMLStrategy';
export default class SingleContextHTML extends PortalHTMLStrategy {
    constructor(){
            super()
    }
    renderHTML(args){}
}
/**
* Multi.js (same as single) ^^ above
*/
/**
* PortalHTMLStrategy.js
*/
'use strict';
export default class PortalHTMLStrategy{
    constructor(){}
    renderHTML(args){}
}
/**
* Tester Mocha and Chai
*/
'use strict';
import PortalHTML from "./PortalHTML";
import chai from 'chai';
let basicPortalHTMLTest = () => {
    let singleContextHTML = new PortalHTML("1");
    let multiContextHTML = new PortalHTML("multi");
    describe('PortalHTML: Initialization of PortalHTML', () => {
        it('Should be an instance of class SingleContextHTML', (done) => {
            chai.expect(singleContextHTML._strategyPeak()).to.equal('SingleContextHTML');
            done();
        });
        it('Should be an instance of MultiContextHTML', (done) => {
            chai.expect(singleContextHTML._strategyPeak()).to.equal('MultiContextHTML');
            done();
        });
    });
};
basicPortalHTMLTest();

我正在尝试测试策略模式的实现,但是在我使用mocha运行测试脚本后,我遇到了一个错误,该错误陈述如下。

var singleContextHTML = new _PortalHTML2.default("1");
                                      ^                               
TypeError: _PortalHTML2.default is not a constructor

我使用node6和以下babel包:

    "babel-cli": "^6.14.0",
    "babel-core": "^6.17.0",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.16.0",
    "babel-preset-react": "^6.11.1",
    "babel-preset-stage-2": "^6.11.0"

我一直在尝试调试这个大约半天。如果有人立即发现我做错了什么,我会非常感谢。

我使用了错误的巴别塔预设。切换到es2016或以上版本修复了此错误。

最新更新