网页学习体会

  • 首页
  • 个人博客
您的位置: 首页  >  IT文章  >  Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解决方法

Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解决方法
分类: IT文章 • 2022-05-11 11:51:27

发现问题

运行一下以前的一个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>‘的解决方法

1 import {normalTime} from './timeFormat';
2 module.exports={
3   normalTime
4 };

就是 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>‘的解决方法

1 import {normalTime} from './timeFormat';
2 export default normalTime;

再次运行:

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

总结

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

原来网址:http://www.jb51.net/article/116453.htm

相关推荐

  • TypeError: Cannot assign to read only property 'exports' of object '#'
  • Vue 使用自定义组件时报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#'
  • vue-cli3 打包时使用‘babel-loader’遇到Cannot assign to read only property ‘exports’ of object '#'问题的解决方法。 原文链接:http://www.pianshen.com/article/9677274805/
  • vue项目中引入 html2canvas ,控制台报错 Cannot assign to read only property 'className' of object '#< SVGSVGElement >'
  • Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解决方法
  • Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解决方法
  • Vue的报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#'
  • vue-cli 配合webpack4 报错 Cannot assign to read only property 'exports' of object '#' 解决方法
  • vue-cli3 打包时使用‘babel-loader’遇到Cannot assign to read only property ‘exports’ of object '#'问题的解决方法。
  • 反转链表
  • 链表中倒数第k个结点
    • 网站免责声明 网站地图 最新文章 用户隐私 版权申明
    本站所有数据收集于网络,如果侵犯到您的权益,请联系网站进行下架处理。   

    Copyright © 2018-2021   Powered By 网页学习体会    备案号:   粤ICP备20002247号