Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#<Object>‘的解决方法
2017-06-17 14:30
1196 查看
发现问题
运行一下以前的一个Vue+webpack的 vue仿新闻网站 小项目,报错
由于自己vue学习不深入,老是这个报错,找了好久(确切的说是整整一下午^...^)才找到原因 -v-
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的方式编写即可.
import {normalTime} from './timeFormat'; export default normalTime;
再次运行:
总结
以上就是这文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如有疑问大家可以留言交流,谢谢大家对脚本之家的支持。
您可能感兴趣的文章:
相关文章推荐
- Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
- vue报错: Cannot assign to read only property 'exports' of object '#<Object>'
- vue引入插件Cannot assign to read only property 'exports' of object '#<Object>'
- vue引入插件Cannot assign to read only property 'exports' of object '#<Object>'
- Cannot assign to read only property 'exports' of object '#<Object>' (mix require and export) #4039
- Cannot assign to read only property 'exports' of object '#<Object>' 解决方案
- Uncaught TypeError: Cannot read property 'click' of null问题的解决
- Ckeditor: Uncaught TypeError: Cannot read property 'keyCode' of undefined 解决方法
- ASP.NET MVC运行出现Uncaught TypeError: Cannot set property __MVC_FormValidation of null的解决方法
- 关于Uncaught TypeError: Cannot read property 'toLowerCase' of undefined的问题
- ASP.NET MVC运行出现Uncaught TypeError: Cannot set property __MVC_FormValidation of null的解决方法
- Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
- echarts.min.js:25 Uncaught TypeError: Cannot read property 'features' of undefined 报错解决方法
- 使用form的方法(例如:reset,clear等)报错Uncaught TypeError: Cannot read property 'tip' of undefined(…)的原因
- 解决sweetalert 无故报错 elem.className.replace Uncaught TypeError: Cannot read property 'className' of ...
- tankgame2.js:37 Uncaught TypeError: Cannot read property 'direct' of undefined(…)
- Uncaught TypeError: Cannot read property 'substring' of undefined
- Uncaught TypeError: Cannot read property 'offsetTop' of null
- H5拖放事件 "Uncaught TypeError: Cannot read property 'setData' of undefined"
- js的form(load报错jquery.easyui.min.js:2837 Uncaught TypeError: Cannot read property 'tip' of undefined