vue cli3 babel7 配置 移除嚴(yán)格模式插件

報(bào)錯信息:

Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them

出現(xiàn)這個(gè)問題的原因,是在引用mui中的mui.js文件時(shí)報(bào)的錯誤,由于在webpack中,采用的時(shí)嚴(yán)格模式,而mui.js用了非嚴(yán)格模式的寫法。

解決方法:

  • 1.把mui.js里面的內(nèi)容改成嚴(yán)格模式,但這不可能,畢竟我們要引用他們。
    1. 只能把webpack改為非嚴(yán)格模式了

安裝:

cnpm i babel-plugin-transform-remove-strict-mode -D

在.babelrc中進(jìn)行配置:

plugins: [
        "transform-remove-strict-mode"  //配置插件,這里很重要
]

就解決了。

......
然鵝,
啟動項(xiàng)目npm run serve 報(bào)錯

Module build failed (from ./node_modules/_babel-loader@8.0.6@babel-loader/lib/index.js):
TypeError: this.setDynamic is not a function

原因:vue項(xiàng)目用的是最新的babel7版本,在.babel.config.js中使用的還是之前的插件.babel7之后的插件一般都是以@babel開頭的,下載新版的babel安裝包之后再運(yùn)行就可以了

安裝改為

cnpm i @babel/plugin-transform-modules-commonjs @babel/plugin-transform-strict-mode -D

在babel.config.js中進(jìn)行配置(vue-cli3 中 沒有.babelrc文件)

plugins: [
    ["@babel/plugin-transform-modules-commonjs", { "strictMode": false }]
],
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容