![](/img/trans.png)
[英]Error Typescript - Uncaught ReferenceError: exports is not defined
[英]Error when migrating from Babel 5 to 6 (ReferenceError: exports is not defined)
我正在使用Gulp和Babel将客户端es6代码编译为es5。 升级后我得到了这个错误(在浏览器中): Uncaught ReferenceError: exports is not defined
出现此错误的原因是,Babel将我的客户端脚本编译为CommonJS模块,并在每个文件的开头添加以下行:
Object.defineProperty(exports, "__esModule", { // <-- ReferenceError: exports is not defined
value: true
});
但我没有在客户端上使用任何UMD / CommonJS模块加载器,因此此代码会导致错误。 使用Babel 5,为了避免这种情况,我使用了选项modules: 'ignore'
在我的gulpfile中modules: 'ignore'
:
return gulp.src(src, {base: 'src'})
.pipe(babel({
modules: 'ignore' // <-- dropped from Babel 6
}))
.pipe(gulp.dest(dest));
所以它按原样编译我的脚本,原始和清晰。 但是这个选项从Babel 6中删除了,现在它导致错误[ReferenceError: [BABEL] ..myscript.js: Unknown option: base.modules]
,所以我不得不评论这一行。
有什么替代modules: 'ignore'
Babel 6中的modules: 'ignore'
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.