When I try to call the example ‘multiply’ module in my custom element (recreated exactly from here )) I get the console error:
caught ReferenceError: elementorySupport is not defined
at e.J (universalModuleDefinition:2:54)
at api_viewer.js?no-umd=true&analyze-imported-namespaces=true&init-platform-api-provider=true&get-app-def-id-from-package-name=false:1:3305
at api_viewer.js?no-umd=true&analyze-imported-namespaces=true&init-platform-api-provider=true&get-app-def-id-from-package-name=false:1:3385
at api_viewer.js?no-umd=true&analyze-imported-namespaces=true&init-platform-api-provider=true&get-app-def-id-from-package-name=false:1:3388
It works in normal page javascript, just not the public custom-element javascript my custom element calls. Does anyone know what’s causing this or how to fix it?
Here’s my custom element code, api_viewer.js:
import {multiply} from 'backend/aModule';
let render, camera, scene, cube, animationRequestId;
class ApiViewJS extends HTMLElement {
constructor(){
super();
}
connectedCallback(){
this.addEventListener('click', () => {
this.dispatchEvent(new CustomEvent('clickedCanvas'));
})
}
attributeChangedCallback(name, oldValue, newValue) {
if(name === 'animation'){
cancelAnimationFrame(animationRequestId);
}
}
static get observedAttributes(){
return ['animation'];
}
}
console.log('HERE');
multiply(2,2).then(function(files){
console.log(files);
});
customElements.define('api-viewer', ApiViewJS);
and here is my backend module, aModule.jsw:
/*********
.jsw file
*********
Backend .jsw files contain functions that run on the server side but can be called from page code and frontend files.
Use backend functions to keep code private and hidden from a user's browser. More info:
https://support.wix.com/en/article/velo-web-modules-calling-backend-code-from-the-frontend
**********/
/*** Call the sample multiply function below by copying the following into your page code:
import { multiply } from 'backend/multiplication';
$w.onReady(function () {
multiply(4, 5).then(product => {
console.log(product);
})
.catch(error => {
console.log(error);
});
});
***/
// Sample backend code in a multiplication.jsw file:
export function multiply(factor1, factor2) {
return factor1 * factor2;
}