Vue報錯:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#<Object>‘的解決方法
發(fā)現(xiàn)問題
運行一下以前的一個Vue+webpack的 vue仿新聞網(wǎng)站 小項目,報錯
由于自己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
,
解決辦法就是統(tǒng)一改成ES6的方式編寫即可.
import {normalTime} from './timeFormat'; export default normalTime;
再次運行:
總結(jié)
以上就是這文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作能帶來一定的幫助,如有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
- Vue項目報錯:Uncaught SyntaxError: Unexpected token <
- Vue 報錯TypeError: this.$set is not a function 的解決方法
- 解決vue安裝less報錯Failed to compile with 1 errors的問題
- Vue.js報錯Failed to resolve filter問題的解決方法
- vue踩坑記-在項目中安裝依賴模塊npm install報錯
- VUE 項目在IE11白屏報錯 SCRIPT1002: 語法錯誤的解決
- Vue 解決通過this.$refs來獲取DOM或者組件報錯問題
- Vue——解決報錯 Computed property "****" was assigned to but it has no setter.
- vue-cli 打包后提交到線上出現(xiàn) "Uncaught SyntaxError:Unexpected token" 報錯
- Vue實戰(zhàn)之項目開發(fā)時常見的幾個錯誤匯總