问题
I have the following, experimental code:
//JS File which exports
function consoletest(){
console.log("HelloRequire!")
}
function commonAJAXCall(){
return $.get('https://jsonplaceholder.typicode.com/todos/1', {
}).then((response) => {
response = JSON.stringify(response)
console.log(response)
console.log("AJAX happened")
return response
})
}
module.exports = {
doStuff: async () => {
//await commonAJAXCall()
consoletest()
}
}
//JS File which imports
let eventListeners = require('./lib/eCommerceLogic')
$("#AJAXproductnames").on("click", function(){
eventListeners.doStuff()
})
Now I followed this really GREAT tutorial from march 2019 on how to use async/await and module.exports: https://www.youtube.com/watch?v=YGHnvrDGmJw
But for some reason, it doesnt work for me :/ When I have the
doStuff: async () => {
//await commonAJAXCall()
consoletest()
}
async keyword in use, I get the error:
Type Error: "exports" is read-only
When I remove it, everything works fine, so the error definitely seems to be related to the async keyword.
My code lies inside a ZURB Foundation 6.4 Project, so theres webpack4, babel7 and gulp in action. I don't know if this might cause the error, because in the tutorial, everything worked fine and I just dont understand why it wont for me :/
async/await are definitely available, I already spent a day configuring babel7 to work with this ES7 feature ^^
来源:https://stackoverflow.com/questions/57427430/why-does-using-async-inside-of-module-exports-cause-type-error-exports-i