Skip to content

Component compiles incorrectly for export { ... as default } ESM syntax #4020

Open
@nolanlawson

Description

@nolanlawson

Description

Consider this component:

class Component extends LightningElement {}
export { Component as default }

Per ES module syntax, it is equivalent to this component:

export default class Component extends LightningElement {}

However, the second one correctly renders, whereas the first does not. (Repro: 08c93cd .) The component appears to not be treated as a LightningElement per the @lwc/compiler – it is simply treated as a plain JavaScript (non-LWC) module.

Steps to Reproduce

08c93cd

Expected Results

export default class Component extends LightningElement {}

is equivalent to

class Component extends LightningElement {}
export { Component as default }

Actual Results

Nothing is rendered, and the component is not registered at runtime as a proper LightningElement.

Version

This issue exists in master today, as well as LWC v5.0.9 (Spring '24) and v3.0.4 (Winter '24). It even repros in LWC v2.11.8 (Summer '22). So this is a longstanding issue.

Possible Solution

Use the export default class ... syntax instead.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BUG P3Up for grabsIssues that are relatively small, self-contained, and ready for implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions