why does using “async” inside of “module.exports” cause: Type Error: “exports” is read-only

你说的曾经没有我的故事 提交于 2019-12-12 19:23:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!