I have a js library that I created static resource for it:
The js library content (the calc.js file for example) like
export default calculate = function(x,y){return x+y;}
In LWC, I import the static resource like:
import calcLib from "@salesforce/resourceUrl/calcLib";
and load it up with:
loadScript(this, calcLib+"/js/calc.js")
.then(() => {
debugger;
})
.catch((error) => {
debugger;
this.error = error;
});
It's always failed loading the script with the message like:
WARNING: Failed to load script at /resource/165916882xxxx/calcLib/js/calc.js: export declarations may only appear at top level of a module [export declarations may only appear at top level of a module]
I have tried modified the library (the calc.js file) like removing export keyword and it load successfully. I have many libraries in my system. Do I have to remove all export keyword to load them in LWC? It's really a nightmare. Is there another way to work around here?