Vue的报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
https://blog.csdn.net/u013809856/article/details/80312774(copy)
Vue的报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
刚刚运行一下以前的一个Vue+webpack的demo,运行之后没有出现想象中的效果,并且报错
Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
点开错误的文件,标注错误的地方是这样的一段代码:
-
import {normalTime} from './timeFormat';
-
-
module.exports={
-
normalTime
-
};
就是module.exports;
百度查不到,google一查果然有。
原因是: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;
最后运行成功。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步