TypeError: “exports” is read-only => When exporting a module with method calling another method

非 Y 不嫁゛ 提交于 2019-12-11 07:46:31

问题


I'm new to webpack and this module bundler stuff and I'm currently just experimenting around what's possible and what isn't.

Here, I'm trying the following:

//appECommerce.js
import eCommerceLogic from './lib/eCommerceLogic.js'

//eCommerceLogic.js
import name from './eCommerceJSExportTests.js';

module.exports = {
  productnamesOnclick:  function(){
    $("#AJAXproductnames").on("click",function(){
       getProductnameElements()
    })
  },
  productNamesGetter: function(){
    async function getProductnameElements(){
      let productNameElements = document.getElementsByClassName('customProductCardName')
      console.log("result is ", productNameElements)
      let test = await name.commonAJAXCall()
      console.log(test)
    }
  }
}

//eCommerceJSExportTests.js
module.exports = {
  commonAJAXCall:  function() {
        //return "helloExport"
        return $.get('https://jsonplaceholder.typicode.com/todos/1', {

            }).then((response) => {
              response = JSON.stringify(response)
              console.log(response)
              console.log("AJAX happened")
              return response
        })
  }
}

So basically, I just want to know why I get this error (see title)^^ Furthermore though, I'd also like to know three specific things:

1) Is it possible to have module B import from module C and then export to module A, where the content of module B's import eventually consists of both its "own" code and the code imported from module C, since module B makes use of the imported properties and methods from module C there?

2) In code which is exported like shown above, is it actually possible to have method A containing a call to method B?

3) Can code which attaches event listeners to the DOM even be exported?

来源:https://stackoverflow.com/questions/57425344/typeerror-exports-is-read-only-when-exporting-a-module-with-method-calling

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