20

This restriction referenced from Distribute Components on AppExchange:

A custom Lightning web component can’t access a Lightning web component or module in a custom namespace. It can access Lightning web components and modules only in the c and lightning namespaces.

says you can't have your custom LWC's in a package and use them in LWCs outside the package. This is a substantial and surprising restriction: packages are an important distribution mechanism in Salesforce (particularly for ISVs), so components and packages not working together seems like a major miss.

  1. For people who are using LWCs and multiple packages together, how have you organised to work-around this problem?
  2. Is this a permanent situation, or something that will change in the future?
  3. Any estimates on how far in the future?
  4. Is there a big technical challenge to overcome, or is it more that this hasn't made it up the priority list yet?

PS Voting here Use a Lightning Web Component from another Package/Namespace? might help.

PPS Just hit this again today. We have a component in a managed package that was developed using slots as an extension mechanism because the extension needs to be markup not data that generates markup. But that can't be wrapped in another LWC from outside the package because of this restriction. (And I assume wrapping in Aura will not allow the slots to be used?) This is so broken if you are an ISV.

2
  • 4
    this is expected to change in the future. i think the only workaround is to wrap them in an aura component and publish the events as application events. I have had luck with this and using lightning out with the aura containers for LWC when needed event bubbling helps with the event listeners.
    – Ronnie
    Apr 9, 2020 at 20:42
  • 1
    mind you my example is for communicating from managed to standard namespace (c) for listening to the component event
    – Ronnie
    Apr 9, 2020 at 20:45

3 Answers 3

9

Cross namespace import and communication is currently restricted because of a security limitation in LWC. With our current Lightning Locker architecture there just isn’t a secure way to enable it. The good news is that UI Security team is actively working on a new architecture that will enable secure namespace import and communication. It isn’t a small undertaking and requires significant changes in order for cross namespace communication to meet our strict security standards. The team is about two releases away before we can begin a pilot for customers and ISVs, in the meantime the UI Security team will be active with external communication as we have updates. I’ll follow up here as they are available.

5
  • Thanks Kiril, very helpful to have a timescale in mind. By 2 releases + pilot I'm assuming this means at least a year before GA if all goes well?
    – Keith C
    Jun 5, 2020 at 19:12
  • 3
    Any updates on timing?
    – Keith C
    Apr 3, 2021 at 21:21
  • @Kiril Any updates on timing? Aug 9, 2021 at 13:41
  • @Kiril Any updates on timing? Feb 3 at 16:38
  • Error message: scoped imports not allowed when a runtime namespace is specified Feb 3 at 16:47
1

For your question about slots, with an aura wrapper you may be able to use the components facets in aura, in order to fill the slot of your lwc yourself?

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_facets.htm

I believe you could create the proper hierarchy of aura component and lwc component to use this. Something like this? (Not actually tested)

<aura:component>
    <aura:attribute name="myBody" type="Aura.Component[]"/>

    <div>
        <c-my-component-slot>{!v.myBody}</c-my-component-slot>
    </div>
</aura:component>

So within the aura wrapper outside of your package it would look like this:

<namespace:Component>
    <aura:set attribute="myBody">
        Hello Body!
    </aura:set>
</namespace:Component>

Please let me know if this solves your issue!

1
  • Thanks Etienne; not fully following and won't be touching this again in the near future so might be a while before I can try.
    – Keith C
    Jun 4, 2020 at 14:04
0

Well I read the manuals and now I understood your problem.

My sugestion is the same of Ronnie. Make the Aura components or capture global events. You can be comunicating between all components includes javacript on visual force. Using pure javascript

Other Idea for you: Create one wrapper on your package to verify components on "c" namespace and if not have the same name of your component you rename your namespace unfortunately.

This scenario is likely to change. This is now because lwc is relatively new.

I hope I helped this time lol

3
  • Hi Chiarato, Thanks for taking the time to look at this. But in question 1, I'm really looking for information from people who do use packages. And your other answers seem to be opinions with no data to back them up... -1 from me.
    – Keith C
    Apr 21, 2020 at 10:16
  • Hello @KeithC I replace my answer.see if it helps you!
    – Chiarato
    Apr 22, 2020 at 3:27
  • Thanks Chiarato. Not too much new information there, but I have removed the -1.
    – Keith C
    Apr 22, 2020 at 6:40

You must log in to answer this question.

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