背景:在一个旧项目中,发现重新npm install 的时候,报了Cannot assign to read only property 'exports' of object '#<Object>',而本地运行的时候没问题,发布服务器的时候,发现问题,报了Cannot assign to read only property 'exports' of object '#<Object>'。
出现bug的原因是:
第一种是:webpack不能混合使用import 和module.exports
解决方式:把module改成import就行
第二种是:就是你要使用@babel/plugin-transform-runtime这个插件的时候,同时你又在某个commonJS写的文件里使用这个插件时,babel会默认你这个文件是ES6的文件,然后就使用import导入了这个插件,从而产生了和第一种情况一样的混用错误
在babel.config.js中添加:sourceType: 'unambiguous'配置如下:
module.exports = {
sourceType: 'unambiguous'
}