![](/img/trans.png)
[英]cypress + lerna: ParseError: 'import' and 'export' may appear only with 'sourceType: module'
[英]Babel 7 not transpiling dependencies in node_modules: 'import' and 'export' may appear only with 'sourceType: module'
我正在嘗試在我的項目中使用@iconify-icons包,但是它使用 es6 模塊並且我的 babel 配置拒絕轉換它們,以便 browserify 可以正常使用它。 這是我使用 browserify + babel 構建的方式:
const babelConfig = {
presets: [
["@babel/preset-env"],
["@babel/preset-react"],
],
ignore: [],
};
gulp.task('browserify', (done) => {
return gulp.src('./resources/reactapp/app.js')
.pipe(bro({
transform: [
babelify.configure(babelConfig),
]
}))
});
但是,在這種情況下,當我嘗試從 @iconify-icons 導入模塊時,我從 browserify 收到以下錯誤:
/node_modules/@iconify-icons/mdi-light/upload.js:6
export default data;
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
對我來說,Babel 在將文件發送到 browserify(只能處理 es5 語法)之前沒有正確轉換文件。 babel 6 的建議解決方案是在 babel 配置中使用 global: true,但該選項在 babel 7 中不存在。我的猜測是 babel 忽略 node_modules,即使我已將 ignore 設置為空列表。
萬一一些可憐的人也發現自己在這里: global 是一個作為轉換屬性傳遞的屬性。
gulp.task('browserify', (done) => {
return gulp.src('./resources/reactapp/app.js')
.pipe(bro({
transform: [
[babelify.configure(babelConfig), {global:true}]
]
}))
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.