Can we have named export in Lightning Web Component?

In ES6 module there are two ways of exporting module: Default Export Named Export I am able to find deault export in lwc

export default class HelloWorld extends LightningElement {}

But I have not seen named export in LWC so want to know if they are used in lwc?

According to ES6 There can be several named exports in a ES6 module. A module can export selected components using the syntax given below −

export component1
export component2
export componentN

1 Answer 1


The main class for a component with a UI must be the default export. However, you are free to export as many symbols as you like, which can be useful for service components, which are those that do not have an html file. The named export rules work per the ES6 specification:

export { symbol1, symbol2 as symbol3, ... }

However, you must use the { symbol } notation. The exact form you specified in your question is not supported.

In fact, that's not valid ES6. The valid types of exports are:

// Exporting individual features
export let name1, name2, …, nameN; // also var, const
export let name1 = …, name2 = …, …, nameN; // also var, const
export function functionName(){...}
export class ClassName {...}

// Export list
export { name1, name2, …, nameN };

// Renaming exports
export { variable1 as name1, variable2 as name2, …, nameN };

// Exporting destructured assignments with renaming
export const { name1, name2: bar } = o;

// Default exports
export default expression;
export default function (…) { … } // also class, function*
export default function name1(…) { … } // also class, function*
export { name1 as default, … };

// Aggregating modules
export * from …; // does not set the default export
export * as name1 from …; // Draft ECMAScript® 2O21
export { name1, name2, …, nameN } from …;
export { import1 as name1, import2 as name2, …, nameN } from …;
export { default } from …;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .