vue報錯: Cannot assign to read only property 'exports' of 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
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;
最後執行成功。