我在使用electron-vue开发时碰到这个问题:
我在一个文件中定义一个async函数,然后按commonJS规范暴露出去。该代码如下:
async function testAsync(){
var a = 1;
await a+2;
return a
}
module.exports = {
test
}
但是报一个这样的错:TypeError: Cannot assign to read only property 'exports' of object '#<Object>'而当我去掉该函数的async以及await关键字之后又正常了。。。有点蒙蔽。。。
CommonJS 模块输出的是值的拷贝,你试一下用es6的导出,即