Babel7.x完美解决严格模式报错:'caller', 'callee', and 'arguments' properties may not be accessed on strict mode

问题描述

做项目用到了MUI的scroll控件 故此我引入了mui.min.js
然而 猝不及防地报错了:
在这里插入图片描述
错误信息:

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

原因

mui.js用到了’caller’, ‘callee’, 和 ‘arguments’
但webpack打包好的bundle.js默认是启用严格模式(strict mode)的
在严格模式下 不能使用’caller’, ‘callee’, 和 ‘arguments’
因此 这两者起了冲突 从而报错


解决方法

安装babel-plugin-transform-remove-strice-mode插件的办法在老版本的Babel是可以的
npm install babel-plugin-transform-remove-strict-mode
或是npm install @babel/plugin-transform-strict-mode
但在新版本的Babel中没用 依旧会报错

解决方法其实很简单:

在.balelrc中添加排除项 排除你的mui.js即可

"ignore": [
      "./src/lib/mui/js/mui.min.js"
    ]

解决了strict mode的问题之后 可能还会有个不影响使用的报错:
在这里插入图片描述
错误信息:

[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive.

虽说不影响使用 但不太美观 顺便解决一下吧
添加一个全局的样式即可:

* {
	touch-action: pan-y;
}

touch-action能够提高页面的流畅度(只有chrome支持)
pan-y样式的作用是启用单指垂直平移手势
即 单指在页面纵向滑动时 能提高页面的流畅度


原创文章 236 获赞 36 访问量 201万+

猜你喜欢

转载自blog.csdn.net/Piconjo/article/details/105880635
今日推荐