webpack报错:Cannot assign to read only property 'exports' of object '#<Object>'
这个倒霉错误在mac电脑上开发的时候非常顺利,可是用windows的时候就会报错。
百度查不到,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。
于是查了一下代码,在自己的main.js中有这一段代码:
import selector from ‘../packages/selector‘;
import alert from ‘../packages/alert‘;
const components=[
selector,
alert,
]
const install=function(Vue,option={}){
components.map(component => {
Vue.component(component.name, component);
})
Vue.prototype.$alert=alert;
Vue.prototype.$info=alert.error;
Vue.prototype.$error=alert.error;
}
module.exports={
version:‘0.0.1‘,
install,
}
这段代码就是在最开始使用了import语句,但是最后使用了module.exports语句。所以就报错了。
改正一下:
var selector = require(‘../packages/selector‘);
var alert=require(‘../packages/alert‘);
const components=[
selector,
alert,
]
const install=function(Vue,option={}){
components.map(component => {
Vue.component(component.name, component);
})
Vue.prototype.$alert=alert;
Vue.prototype.$info=alert.error;
Vue.prototype.$error=alert.error;
}
module.exports={
version:‘0.0.1‘,
install,
}
搞定了。
所以提醒我,以后一定要配对使用require和module.exports以及import和export default。
不要混用,省得出问题。
文章来自:http://www.cnblogs.com/oukichi/p/6389428.html