4

With reference to the document Access Labels for lwc, I created few custom labels and used them in my web component; most of the labels were unable to resolve. I don't understand why exactly.

To simulate the behaviour, created 2 labels as FirstTest and SecondTest and a simple lwc as follows:

import { LightningElement } from 'lwc';

import FirstTest from '@salesforce/label/c.FirstTest';
import SecondTest from '@salesforce/label/c.SecondTest';

export default class customLabelCheck extends LightningElement {

    // init method
    connectedCallback() {
        const myLabel = {
            FirstTest,
            SecondTest
        }
        console.log("label", JSON.stringify(myLabel));
    }

    // Expose the labels to use in the template.
    label = {
        FirstTest,
        SecondTest
    };
}

On load the console output is as:

label {"FirstTest":"$Label.rdev.FirstTest does not exist.","SecondTest":"$Label.rdev.SecondTest does not exist."}

I am testing this in my scratch org with a namespace as rdev. Don't think we have to do any additional thing to resolve the labels?

8
  • Do you get the values on your HTML when you access the label property? – Jayant Das Apr 26 '19 at 15:06
  • While accessing the values in HTML, I get the same value as in console.log's. – Raul Apr 26 '19 at 15:10
  • Have you tried with the namespace? As rdev.FirstTest in the import statement? The docs mentions -- The name of the label in your org in the format namespace.labelName – Jayant Das Apr 26 '19 at 15:12
  • 1
    Hey @Raul, were you ever able to get this resolved? If so, what was your solution? – Charles Naccio Jun 5 '19 at 21:36
  • 1
    @Charles don't know anymore as I changed my job, thought this to be a bug as same code worked on our integration sandbox but not on our scratch orgs. Good luck! – Raul Jun 8 '19 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.