Getting error for user fields in LWC component when using schema

lightning-web-componentsschema

I am trying to retrive field information for user fields using following code.
But except for the Name field of User, it is throwing error for every other field.
Any idea why its not letting me access user fields using schema.

I went ahead and tried Apex route also but same result.

import { LightningElement, wire, track } from 'lwc';
import USER_ID from '@salesforce/user/Id'; 
import NAME_FIELD from '@salesforce/schema/User.Name';
import PHONE_FIELD from '@salesforce/schema/User.Phone';
import ROLE_FIELD from '@salesforce/schema/User.UserRole.Name'; 

export default class myComponent extends LightningElement {
    @track error ; 
    @track name;
    @track phone;
    @track role;
    @wire(getRecord, {
         recordId: USER_ID,
         fields: [NAME_FIELD]
    }) wireuser({
         error,
         data
     }) {
         if (error) {
            this.error = error ; 
         } else if (data) {
             this.name = data.fields.Name.value;
             //this.phone = data.fields.Phone.value;             
             //this.role = data.fields.UserRole.value.fields.Name.value;
         }
     }
} 

Error Details:


Invalid reference User.Phone of type sobjectField in file
myComponent.js: Source


Addtional Details:
I am using following extension for editing the code.
Salesforce LWC Editor

Best Answer

This is a known issue with the LWC Deployment with the tooling API of Salesforce. If the underlying tool in your case the chrome extension uses tooling API for LWC Bundle deployment causing the issue.

Currently only workaround for this is to switch to alternate tools like SFDX CLI or use Salesforce VSCode extension to deploy your LWC component as those use Metadata API than using the tooling API.

Related Topic