剛剛運(yùn)行一下以前的一個(gè)Vue+webpack的demo,運(yùn)行之后沒(méi)有出現(xiàn)想象中的效果,并且報(bào)錯(cuò)
1錯(cuò)誤——Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
點(diǎn)開(kāi)錯(cuò)誤的文件,標(biāo)注錯(cuò)誤的地方是這樣的一段代碼:
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.
翻譯過(guò)來(lái)就是說(shuō),代碼沒(méi)毛病,在webpack打包的時(shí)候,可以在js文件中混用require和export。但是不能混用import 以及module.exports。
因?yàn)閣ebpack 2中不允許混用import和module.exports,
1錯(cuò)誤解決——解決辦法就是統(tǒng)一改成ES6的方式編寫(xiě)即可.
import {normalTime} from './timeFormat';
export default normalTime;</pre>
最后運(yùn)行成功。