温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》
  • 首页 > 
  • 教程 > 
  • 开发技术 > 
  • web开发 > 
  • Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#<Object>‘的解决

Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#<Object>‘的解决

发布时间:2020-09-30 18:32:41 来源:脚本之家 阅读:486 作者:轻轻走143 栏目:web开发

发现问题

运行一下以前的一个Vue+webpack的 vue仿新闻网站  小项目,报错

由于自己vue学习不深入,老是这个报错,找了好久(确切的说是整整一下午^...^)才找到原因 -v-

Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'

Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#<Object>‘的解决 

点开错误的文件,标注错误的地方是这样的一段代码:

Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#<Object>‘的解决

import {normalTime} from './timeFormat';

module.exports={
  normalTime
};

就是module.exports;

解决方法

同过谷歌查找,和论坛各种搜索:

原因如下:The code above is ok. You can mix require and export. You can‘t mix import and module.exports.

翻译过来就是说,代码没毛病,在webpack打包的时候,可以在js文件中混用require和export。但是不能混用import 以及module.exports

因为webpack 2中不允许混用import和module.exports ,

解决办法就是统一改成ES6的方式编写即可.

Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#<Object>‘的解决

import {normalTime} from './timeFormat';

export default normalTime;

再次运行:

Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#<Object>‘的解决

总结

以上就是这文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如有疑问大家可以留言交流,谢谢大家对亿速云的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI