[解决]记一次 Uncaught SyntaxError: Use of const in strict mode 的问题解决

事情起因

前端的代码在我本机初次下载后,dev 调试没问题,build 出的包,在 android4.4 系统中无法浏览,查看日志:

Uncaught SyntaxError: Use of const in strict mode -- From line 1 of 

 

 

解决方式

使用cnpm

因为前端一直使用的是 cnpm,而我用的npm

 

对比分析

我用同一份代码分别使用了 yarn、npm、cnpm ,对比结果如下

  -i build 真机浏览
npm Yes

No

会报错,提示缺少swiper.css

No

 Use of const in strict mode

cnpm Yes Yes Yes
yarn Yes Yes

No

 Use of const in strict mode

       

 

  andorid 4.4 andorid 5 andorid 6 Chrome
前端  window7、node v12、npm v6.8 Yes Yes Yes Yes
我的 window10、node v8、npm v6.8 No Yes Yes Yes
我的 window10、node v14、npm v7 No Yes Yes Yes

 

我的各种尝试(用npm)

期间对比了svn中提交的各个版本,发现在某个版本开始,可以重现该错误。

经过分析本次提交的代码,逐行屏蔽、打包、测试,找到了:

import Clickoutside from "element-ui/src/utils/clickoutside";

将这个功能屏蔽后,npm打包的版本也可以使用了。

 

深层次原因

还不明白

 

 

 

 

posted @ 2021-05-27 12:10  小 天  阅读(1273)  评论(0编辑  收藏  举报