I am trying to import modules dynamically in my LWC component.
While pushing the change I get a strange error LWC1509: This experimental syntax requires enabling the parser plugin: 'dynamicImport'
Here is sample code that produces the error
calculator/calculator.js
export default class Calculator {
static add = (a, b) => a + b;
}
sample/sample.js
import { LightningElement } from 'lwc';
// import Calculator from "c/calculator";
export default class Sample extends LightningElement {
connectedCallback() {
import("c/calculator")
.then(Calculator => alert(Calculator.add(1, 2)))
.catch(error => console.error(error));
}
}
I could't find any documentation which mentions dynamic import is not supported in LWC.
Google redirects me to a github issue raised for babel. Is this a limitation with LWC or am I missing something?
Best Answer
Could you please try
without the default/class keyword. Worked for me.