[SalesForce] How to dynamically import a module in lwc

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


export default class Calculator {
    static add = (a, b) =>  a + b;


import { LightningElement } from 'lwc';
// import Calculator from "c/calculator";

export default class Sample extends LightningElement {
    connectedCallback() {
        .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

export Calculator {
    static add = (a, b) =>  a + b;

without the default/class keyword. Worked for me.