Skip to main content

Code reviews rule: Breaking change in LWC import and export statements

Written by David Martin

Breaking change in LWC import and export statements

Why is this an issue?

This rule applies to JavaScript files inside Lightning Web Component bundles.

From LWC version 62.0 and later, Salesforce prevents the use of bare imports, bare exports, and wildcard re-exports of the lwc package.

Examples

Example of incorrect code:

// Don't do this
import 'lwc';
import {} from 'lwc';
export * as lwc from 'lwc';
export {} from 'lwc';

Example of correct code:

import { LightningElement } from 'lwc';
export { LightningElement } from 'lwc';

How can I fix violations?

This rule supports autofix for bare import statements: the offending import is removed automatically. Bare exports are not autofixed and must be corrected manually.

  1. Replace bare imports: Convert to named imports specifying what you need.

  2. Replace bare exports: Use named exports for specific items.

  3. Don't wildcard-re-export lwc: Named re-exports such as export { LightningElement } from 'lwc'; are allowed; wildcard (export *) and empty (export {}) re-exports are not.

Resources

Did this answer your question?