function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VijayNiVijayNi 

LWC1503: Parsing error: Unexpected token

Hi Team,

can you please  help me on why we are getting the below error 

User-added image


19:12:51.998 ended SFDX: Deploy Source to Org
19:20:15.573 Starting SFDX: Deploy Source to Org
=== Deploy Errors
PROJECT PATH  ERRORS                                                
────────────  ──────────────────────────────────────────────────────
              LWC1503: Parsing error: Unexpected token (7:11) (7:11)
19:20:18.812 ended SFDX: Deploy Source to Org


Thanks,
Vijay.
Suraj Tripathi 47Suraj Tripathi 47
Hi Vijay,

Here recordId and objectApiName is a variable and you are using it as a string value, also use semicolon after the consol.log statement. 

If this answer is helpful for you then mark it as the best answer.
VijayNiVijayNi
Hi Tripathi,

I tried but still i am getting the same error .

Js file :

import { LightningElement,api } from 'lwc';
export default class CurrentRecordAndObjectInfo extends LightningElement {
    @api recordId;
    @api objectApiName;
    console.log('recordId');
    console.log('objectApiName');
}

User-added image


Thanks,
Vijay.
Suraj Tripathi 47Suraj Tripathi 47
Hi Vijay,
Js file :

import { LightningElement,api } from 'lwc';
export default class CurrentRecordAndObjectInfo extends LightningElement {
    @api recordId;
    @api objectApiName;
    console.log('recordId'+recordID);
    console.log('objectApiName'+objectApiName);
}

Thanks 
Suraj Tripathi.

If this answer is helpful for you then mark it as the best answer.
VijayNiVijayNi
Hi Suraj,
i have tried the above code but still seeing the error   parameter declartion expected .

User-added image


Thanks,
Vijay.
Suraj Tripathi 47Suraj Tripathi 47
Hi Vijay,
the javascript is a case sensitive so you have to right the same name as you define at @api
you can check that code below,s
Js file :
 
import { LightningElement,api } from 'lwc';
export default class CurrentRecordAndObjectInfo extends LightningElement {
    @api recordId;
    @api objectApiName;
    console.log('recordId'+recordId);
    console.log('objectApiName'+objectApiName);
}

Thanks 
Suraj Tripathi.
VijayNiVijayNi
Hi Suraj,

I have changed the code but still  seeing the error 

.User-added image


{
    "resource": "/c:/Users/91773/OneDrive/Desktop/SFDCFACTS/CounterVaraibleLog/force-app/main/default/lwc/currentRecordAndObjectInfo/currentRecordAndObjectInfo.js",
    "owner": "typescript",
    "code": "1138",
    "severity": 8,
    "message": "Parameter declaration expected.",
    "source": "ts",
    "startLineNumber": 5,
    "startColumn": 27,
    "endLineNumber": 5,
    "endColumn": 28
}
Thanks,
Vijay


 
Raghu_RankawatRaghu_Rankawat

Hi Vijay,
 

You are getting this syntax error as you need to use any Lifecycle hook to call console/JS function,

More info on LWC Lifecycle Hooks: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/reference_lifecycle_hooks

Please try the below code:

/* eslint-disable no-console */
import { LightningElement,api } from 'lwc';
export default class CurrentRecordAndObjectInfo extends LightningElement {
    @api recordId;
    @api objectApiName;
    // console.log('recordId');
    // console.log('objectApiName');

    connectedCallback(){
        console.log('recordId');
        console.log('objectApiName');
    }
}


Regards,

Raghu

Dragan ŠantićDragan Šantić

Hi Vijay,

to access the variables, you need to use this keyword.
Please try the below code:

import { LightningElement,api } from 'lwc';

export default class CurrentRecordAndObjectInfo extends LightningElement {
    @api recordId;
    @api objectApiName;

    // console.log('recordId');
    // console.log('objectApiName');

    connectedCallback() {
        console.log('recordId', this.recordId);
        console.log('objectApiName', this.objectApiName);
    }
}
 

Regards,
Dragan