使用gulp , browserify和babelify ,导出/导入类工作正常,直到我尝试使用不同的名称导入相同的类:
// Acme/DefaultInit.js export default class DefaultInit { constructor() { console.log('hello'); } } // App/Init.js import * as B from "../Acme/DefaultInit"; class Init extends B.DefaultInit { constructor() { super(); console.log('how are you?'); } }所以当我运行gulp构建的脚本时,错误是:
TypeError: Super expression must either be null or a function, not undefined来自babel生成的代码
if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); }我在那里做错了什么? 请注意,没有jslint错误
Using gulp, browserify & babelify, exporting/import classes worked fine until I tried to import the same class under a different name:
// Acme/DefaultInit.js export default class DefaultInit { constructor() { console.log('hello'); } } // App/Init.js import * as B from "../Acme/DefaultInit"; class Init extends B.DefaultInit { constructor() { super(); console.log('how are you?'); } }So when I run the gulp built script, the error is:
TypeError: Super expression must either be null or a function, not undefinedcoming from the babel generated code
if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); }What I'm doing wrong there ? Note that are no jslint errors
最满意答案
您将DefaultInit导出为默认值,因此它实际上可以从B.default获得, B.default不是B.DefaultInit 。
如果你想能够做B.DefaultInit从class DefaultInit之前删除default ,或者替换import * as B来import DefaultInit 。
You're exporting DefaultInit as a default so it'll actually be available from B.default not B.DefaultInit.
If you want to be able to do B.DefaultInit drop the default from before class DefaultInit or alternatively replace import * as B to import DefaultInit.
更多推荐
发布评论