Loading

Scoped Imports Not Allowed in LWC Using Lightning Locker

Udgivelsesdato: Aug 7, 2026
Beskrivelse

Issue

Scoped imports are not allowed in a custom Lightning Web Component (LWC) when that component uses the runtime namespace tag in its LWC XML configuration file. The import fails and the component does not load or compile as expected.

Symptoms

  • A custom LWC that relies on a scoped import does not render or errors out.
  • The component in question declares the runtime namespace tag in its .js-meta.xml configuration file.
  • Removing the scoped import (or the runtime namespace usage) allows the component to work again.

Applies To

  • Lightning Web Components (LWC)
  • Orgs still using Lightning Locker as the JavaScript security architecture for Lightning web components
  • Salesforce Lightning Experience

Root Cause

This is a known limitation of Lightning Locker. Lightning Locker wraps component JavaScript in secure wrappers to enforce namespace isolation, and under this architecture scoped imports in combination with the runtime namespace tag are not supported. The behavior is expected under Lightning Locker; it is not a defect in your component code. Salesforce's newer security architecture, Lightning Web Security (LWS), is designed to replace Lightning Locker for Lightning web components. Lightning Locker remains in use for Aura components in orgs where LWS is not yet enabled for Aura.

Løsning

To resolve the limitation, switch the org's Lightning web component security to Lightning Web Security (LWS), which supports scenarios Lightning Locker restricts.

Recommended: test in a sandbox first

  1. In a sandbox org, open Setup.
  2. In Quick Find, enter Session, then select Session Settings.
  3. Select Use Lightning Web Security for Lightning web components and Aura components.
  4. Save the setting, then clear your browser cache so the updated files load.
  5. Re-test the affected component to confirm the scoped import now works and the component renders as expected.
  6. Once validated in the sandbox, repeat steps 1–5 in your production org.
Note: LWS is generally available and is enabled by default for orgs created in Winter '23 and later, so this limitation typically appears only in orgs still running Lightning Locker for Lightning web components.

What Lightning Web Security supports

Lightning Web Security provides capabilities that Lightning Locker does not:

  • Cross-namespace component use
  • Interactions with global objects (window, document, element) without secure wrappers
  • Improved performance (no secure wrappers)
  • Better support of third-party JavaScript
  • Compatibility with standard JavaScript as it evolves

If you need to revert

To turn the setting off again, return to Setup → Session Settings, deselect Use Lightning Web Security for Lightning web components and Aura components, save, and clear your browser cache. The org returns to Lightning Locker for Lightning web components (and the scoped-import limitation applies again).

Additional Resources

Vidensartikelnummer

000395260

 
Indlæser
Salesforce Help | Article