Are custom labels referenced only in Lightning Components automatically packaged?

This (not marked as delivered) idea Custom Label Auto Packaging in Lightning Components has a “Latest Comment from Salesforce” of:

Farhan Tahir – 5 months ago

This is coming in Spring’18!!

The very ugly workaround seems to be to reference the labels in e.g. an Apex class so they are automatically packaged.

Are custom labels referenced only in Lightning Components automatically packaged?


Also see Manjot’s comment. There are 2 cases: the .cmp files files:


and the .js files:


Also see this July 2017 post Packaging custom labels used in ligthning helpers and controllers.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

I would say it’s partially working after performing some tests. I’ve created a Salesforce ticket in order to report and address this bug. Anyway I’d like to share my findings.

Let’s consider 3 scenarios:

Scenario 1 (working) – The label already exists and then you save the component controller/helper on the package org. So when packaging it should include the labels and tag them as managed.

Scenario 2 (not working) – The label doesn’t exist yet and then you save a component controller/helper on the package org. Later you create the label.

Scenario 3 (not working) – When deploying an unmanaged package to the package org with component bundles and labels.

The behavior of $Label getting included in packages when referenced inside components, controllers or helpers is called as resource spidering (I received this information from Salesforce).
Seems that it’s triggering the resource spidering only when following the step 1.

Hope this helps.

Find below some code used to test this issue.


    <aura:handler name="init" value="{!this}" action="{!c.onInit}" />
    <lightning:button aura:id="new" label="{!$Label.hook.Label1}" onclick="{!c.onNewClick}"/>


    onInit : function(component, event, helper) {
    onNewClick : function(component, event, helper) {
        helper.onNewClick(component, event);


    onNewClick : function() {

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply