關於vue-cli3打包時遇到Cannot assign to read only property 'exports' of object '#'問題的解決方法。

vue-cli3打包時遇到Cannot assign to read only property 'exports' of object '#<Object>'問題的解決方法。

大致是說,在webpack打包的時候,可以在js文件中混用require和export。但是不能混用import 以及module.exports。

因為webpack 2中不允許混用import和module.exports,

  為了使編譯好的程序能在大多數瀏覽器下運行。webpack里面有一個編譯器叫Babel,負責把ES6的語言轉化為commonJS以兼容絕大多數瀏覽器。當你混用這兩個語法的時候你可以使用babel的commonJS模式幫你把import編譯成require。
  然而第二種情況就是你要使用@babel/plugin-transform-runtime這個插件的時候,同時你又在某個commonJS寫的文件里使用這個插件時,babel會默認你這個文件是ES6的文件,然后就使用import導入了這個插件,從而產生了和第一種情況一樣的混用錯誤。解決方法是在babel.config.js里配置unambiguous設置,讓babel和webpack一樣嚴格區分commonJS文件和ES6文件。


免責聲明!

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



猜您在找 vue-cli3 打包時使用‘babel-loader’遇到Cannot assign to read only property ‘exports’ of object '#'問題的解決方法。 Vue報錯:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解決方法 解決 Cannot assign to read only property 'exports' of object '#' 問題 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 '#' Cannot assign to read only property 'exports' of object '#' Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' [one day one question] webpack 打包報錯 Cannot assign to read only property 'exports' of object '#' Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#'
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM