![](/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.