Vue的報錯:Uncaught TypeError: 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 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;

最后運行成功。

 


免責聲明!

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



猜您在找 Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' Cannot assign to read only property 'exports' of object '#' Cannot assign to read only property 'exports' of object '#' ,文件名大小寫問題!!! create-react-app 遇到問題 TypeError: Cannot assign to read only property 'jsx' of object '#' vue報錯TypeError: Cannot read property of undefined 或 Uncaught TypeError: this.myMethod is not a function zTree報錯 : Uncaught TypeError: Cannot read property 'init' of undefined datatable報錯 uncaught TypeError: Cannot read property 'aDataSort' of undefined jQuery mobile報錯 Uncaught TypeError: Cannot read property 'concat' of undefined Uncaught (in promise) TypeError: Cannot read property 'error' of undefined at __webpack_exports__.a Uncaught TypeError: Cannot read property ‘split’ of undefined
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM