Vue報錯:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解決方法

發現問題

運行一下以前的一個Vue+webpack的 vue仿新聞網站  小項目,報錯

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

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

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

再次運行:

 

總結

以上就是這文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

原來網址:http://www.jb51.net/article/116453.htm


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 Vue報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object 的解決方法 Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' Vue 使用自定義組件時報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' 關於vue-cli3打包時遇到Cannot assign to read only property 'exports' of object '#'問題的解決方法。 vue運行報錯error:Cannot assign to read only property 'exports' of object '#' vue-cli3 打包時使用‘babel-loader’遇到Cannot assign to read only property ‘exports’ of object '#'問題的解決方法。 Cannot assign to read only property 'exports' of object '#' [one day one question] webpack 打包報錯 Cannot assign to read only property 'exports' of object '#' js嵌套對象報錯Uncaught TypeError: Cannot read property 'name' of undefined at解決方法 vue報錯 Uncaught TypeError: Cannot read property of null
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM