1. 程式人生 > >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,執行一下以前的一個Vue+webpack的 vue仿新聞網站  小專案,報錯

由於自己vue學習不深入,老是這個報錯,找了好久(確切的說是整整一下午^...^)才找到原因 -v-


2,點開錯誤的檔案,標註錯誤的地方是這樣的一段程式碼:

就是 module.exports; 


解決方法

3,同過谷歌查詢,和論壇各種搜尋:

原因如下:

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的方式編寫即可.


4,再次執行:

ok^_^

 


來源於:

http://www.cnblogs.com/qingqingzou-143/p/7028683.html