Log to console in a Lightning Web Component












5















I am attempting to write a Lightning Web Component, but continually run into errors in my Javascript that I can't debug.



I've been trying to log my error but when I put console.log() anywhere in the methods that are failing, I get the error:




Unexpected console statement.











share|improve this question




















  • 1





    Surprisingly console.log() work in playground

    – Pranay Jaiswal
    9 hours ago






  • 1





    That must be the ESLint error. You can still use console.log() or say alert() statements for any debugging purposes (I can confirm this as I have used this in couple of my LWCs).

    – Jayant Das
    9 hours ago











  • @JayantDas anything to supress linter error?

    – Pranay Jaiswal
    9 hours ago











  • @PranayJaiswal I have utilized it right within the editor by suppressing those. But there must be a config file to do it globally though.

    – Jayant Das
    9 hours ago






  • 1





    @PranayJaiswal Looks like there's one for such cases.

    – Jayant Das
    9 hours ago


















5















I am attempting to write a Lightning Web Component, but continually run into errors in my Javascript that I can't debug.



I've been trying to log my error but when I put console.log() anywhere in the methods that are failing, I get the error:




Unexpected console statement.











share|improve this question




















  • 1





    Surprisingly console.log() work in playground

    – Pranay Jaiswal
    9 hours ago






  • 1





    That must be the ESLint error. You can still use console.log() or say alert() statements for any debugging purposes (I can confirm this as I have used this in couple of my LWCs).

    – Jayant Das
    9 hours ago











  • @JayantDas anything to supress linter error?

    – Pranay Jaiswal
    9 hours ago











  • @PranayJaiswal I have utilized it right within the editor by suppressing those. But there must be a config file to do it globally though.

    – Jayant Das
    9 hours ago






  • 1





    @PranayJaiswal Looks like there's one for such cases.

    – Jayant Das
    9 hours ago
















5












5








5








I am attempting to write a Lightning Web Component, but continually run into errors in my Javascript that I can't debug.



I've been trying to log my error but when I put console.log() anywhere in the methods that are failing, I get the error:




Unexpected console statement.











share|improve this question
















I am attempting to write a Lightning Web Component, but continually run into errors in my Javascript that I can't debug.



I've been trying to log my error but when I put console.log() anywhere in the methods that are failing, I get the error:




Unexpected console statement.








error console lightning-web-components






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 9 hours ago









Jayant Das

15.3k2824




15.3k2824










asked 9 hours ago









BlondeSwanBlondeSwan

1006




1006








  • 1





    Surprisingly console.log() work in playground

    – Pranay Jaiswal
    9 hours ago






  • 1





    That must be the ESLint error. You can still use console.log() or say alert() statements for any debugging purposes (I can confirm this as I have used this in couple of my LWCs).

    – Jayant Das
    9 hours ago











  • @JayantDas anything to supress linter error?

    – Pranay Jaiswal
    9 hours ago











  • @PranayJaiswal I have utilized it right within the editor by suppressing those. But there must be a config file to do it globally though.

    – Jayant Das
    9 hours ago






  • 1





    @PranayJaiswal Looks like there's one for such cases.

    – Jayant Das
    9 hours ago
















  • 1





    Surprisingly console.log() work in playground

    – Pranay Jaiswal
    9 hours ago






  • 1





    That must be the ESLint error. You can still use console.log() or say alert() statements for any debugging purposes (I can confirm this as I have used this in couple of my LWCs).

    – Jayant Das
    9 hours ago











  • @JayantDas anything to supress linter error?

    – Pranay Jaiswal
    9 hours ago











  • @PranayJaiswal I have utilized it right within the editor by suppressing those. But there must be a config file to do it globally though.

    – Jayant Das
    9 hours ago






  • 1





    @PranayJaiswal Looks like there's one for such cases.

    – Jayant Das
    9 hours ago










1




1





Surprisingly console.log() work in playground

– Pranay Jaiswal
9 hours ago





Surprisingly console.log() work in playground

– Pranay Jaiswal
9 hours ago




1




1





That must be the ESLint error. You can still use console.log() or say alert() statements for any debugging purposes (I can confirm this as I have used this in couple of my LWCs).

– Jayant Das
9 hours ago





That must be the ESLint error. You can still use console.log() or say alert() statements for any debugging purposes (I can confirm this as I have used this in couple of my LWCs).

– Jayant Das
9 hours ago













@JayantDas anything to supress linter error?

– Pranay Jaiswal
9 hours ago





@JayantDas anything to supress linter error?

– Pranay Jaiswal
9 hours ago













@PranayJaiswal I have utilized it right within the editor by suppressing those. But there must be a config file to do it globally though.

– Jayant Das
9 hours ago





@PranayJaiswal I have utilized it right within the editor by suppressing those. But there must be a config file to do it globally though.

– Jayant Das
9 hours ago




1




1





@PranayJaiswal Looks like there's one for such cases.

– Jayant Das
9 hours ago







@PranayJaiswal Looks like there's one for such cases.

– Jayant Das
9 hours ago












1 Answer
1






active

oldest

votes


















8














You are most likely encountering ESLint errors in VS Code.



As an example below is how my code looks like with those warnings. However I am still able to save the component and utilize alert or console.log statements specifically for debugging purposes.



You can also choose to suppress those warnings by right clicking on those warnings



OR



By editing the .eslintrc.json available in your project by adding the below rules:



"rules": {
"no-console": "off",
"no-alert": "off"
}




Console showing errors



enter image description here





Option to disable the rules by right clicking on the alert



enter image description here






share|improve this answer


























  • +1. Thanks. I tried same in Illuminated Cloud for LWC, it showed SUCCEEDED_PARTIAL

    – Pranay Jaiswal
    9 hours ago






  • 2





    @PranayJaiswal I updated my answer to include how to add the rules in .eslintrc.json in VS Code.

    – Jayant Das
    9 hours ago






  • 1





    @JayantDas thanks. btw, thanks for all your help. I don't mean to be a bug asking all these questions, it's just hard finding documentation for non-aura components.

    – BlondeSwan
    8 hours ago











  • @BlondeSwan You have been helping me/us to learn/know all this! So equally thanks to you :)

    – Jayant Das
    8 hours ago






  • 2





    Thanks Jayant. Much appreciated

    – Pranay Jaiswal
    8 hours ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "459"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f251270%2flog-to-console-in-a-lightning-web-component%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









8














You are most likely encountering ESLint errors in VS Code.



As an example below is how my code looks like with those warnings. However I am still able to save the component and utilize alert or console.log statements specifically for debugging purposes.



You can also choose to suppress those warnings by right clicking on those warnings



OR



By editing the .eslintrc.json available in your project by adding the below rules:



"rules": {
"no-console": "off",
"no-alert": "off"
}




Console showing errors



enter image description here





Option to disable the rules by right clicking on the alert



enter image description here






share|improve this answer


























  • +1. Thanks. I tried same in Illuminated Cloud for LWC, it showed SUCCEEDED_PARTIAL

    – Pranay Jaiswal
    9 hours ago






  • 2





    @PranayJaiswal I updated my answer to include how to add the rules in .eslintrc.json in VS Code.

    – Jayant Das
    9 hours ago






  • 1





    @JayantDas thanks. btw, thanks for all your help. I don't mean to be a bug asking all these questions, it's just hard finding documentation for non-aura components.

    – BlondeSwan
    8 hours ago











  • @BlondeSwan You have been helping me/us to learn/know all this! So equally thanks to you :)

    – Jayant Das
    8 hours ago






  • 2





    Thanks Jayant. Much appreciated

    – Pranay Jaiswal
    8 hours ago
















8














You are most likely encountering ESLint errors in VS Code.



As an example below is how my code looks like with those warnings. However I am still able to save the component and utilize alert or console.log statements specifically for debugging purposes.



You can also choose to suppress those warnings by right clicking on those warnings



OR



By editing the .eslintrc.json available in your project by adding the below rules:



"rules": {
"no-console": "off",
"no-alert": "off"
}




Console showing errors



enter image description here





Option to disable the rules by right clicking on the alert



enter image description here






share|improve this answer


























  • +1. Thanks. I tried same in Illuminated Cloud for LWC, it showed SUCCEEDED_PARTIAL

    – Pranay Jaiswal
    9 hours ago






  • 2





    @PranayJaiswal I updated my answer to include how to add the rules in .eslintrc.json in VS Code.

    – Jayant Das
    9 hours ago






  • 1





    @JayantDas thanks. btw, thanks for all your help. I don't mean to be a bug asking all these questions, it's just hard finding documentation for non-aura components.

    – BlondeSwan
    8 hours ago











  • @BlondeSwan You have been helping me/us to learn/know all this! So equally thanks to you :)

    – Jayant Das
    8 hours ago






  • 2





    Thanks Jayant. Much appreciated

    – Pranay Jaiswal
    8 hours ago














8












8








8







You are most likely encountering ESLint errors in VS Code.



As an example below is how my code looks like with those warnings. However I am still able to save the component and utilize alert or console.log statements specifically for debugging purposes.



You can also choose to suppress those warnings by right clicking on those warnings



OR



By editing the .eslintrc.json available in your project by adding the below rules:



"rules": {
"no-console": "off",
"no-alert": "off"
}




Console showing errors



enter image description here





Option to disable the rules by right clicking on the alert



enter image description here






share|improve this answer















You are most likely encountering ESLint errors in VS Code.



As an example below is how my code looks like with those warnings. However I am still able to save the component and utilize alert or console.log statements specifically for debugging purposes.



You can also choose to suppress those warnings by right clicking on those warnings



OR



By editing the .eslintrc.json available in your project by adding the below rules:



"rules": {
"no-console": "off",
"no-alert": "off"
}




Console showing errors



enter image description here





Option to disable the rules by right clicking on the alert



enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited 8 hours ago

























answered 9 hours ago









Jayant DasJayant Das

15.3k2824




15.3k2824













  • +1. Thanks. I tried same in Illuminated Cloud for LWC, it showed SUCCEEDED_PARTIAL

    – Pranay Jaiswal
    9 hours ago






  • 2





    @PranayJaiswal I updated my answer to include how to add the rules in .eslintrc.json in VS Code.

    – Jayant Das
    9 hours ago






  • 1





    @JayantDas thanks. btw, thanks for all your help. I don't mean to be a bug asking all these questions, it's just hard finding documentation for non-aura components.

    – BlondeSwan
    8 hours ago











  • @BlondeSwan You have been helping me/us to learn/know all this! So equally thanks to you :)

    – Jayant Das
    8 hours ago






  • 2





    Thanks Jayant. Much appreciated

    – Pranay Jaiswal
    8 hours ago



















  • +1. Thanks. I tried same in Illuminated Cloud for LWC, it showed SUCCEEDED_PARTIAL

    – Pranay Jaiswal
    9 hours ago






  • 2





    @PranayJaiswal I updated my answer to include how to add the rules in .eslintrc.json in VS Code.

    – Jayant Das
    9 hours ago






  • 1





    @JayantDas thanks. btw, thanks for all your help. I don't mean to be a bug asking all these questions, it's just hard finding documentation for non-aura components.

    – BlondeSwan
    8 hours ago











  • @BlondeSwan You have been helping me/us to learn/know all this! So equally thanks to you :)

    – Jayant Das
    8 hours ago






  • 2





    Thanks Jayant. Much appreciated

    – Pranay Jaiswal
    8 hours ago

















+1. Thanks. I tried same in Illuminated Cloud for LWC, it showed SUCCEEDED_PARTIAL

– Pranay Jaiswal
9 hours ago





+1. Thanks. I tried same in Illuminated Cloud for LWC, it showed SUCCEEDED_PARTIAL

– Pranay Jaiswal
9 hours ago




2




2





@PranayJaiswal I updated my answer to include how to add the rules in .eslintrc.json in VS Code.

– Jayant Das
9 hours ago





@PranayJaiswal I updated my answer to include how to add the rules in .eslintrc.json in VS Code.

– Jayant Das
9 hours ago




1




1





@JayantDas thanks. btw, thanks for all your help. I don't mean to be a bug asking all these questions, it's just hard finding documentation for non-aura components.

– BlondeSwan
8 hours ago





@JayantDas thanks. btw, thanks for all your help. I don't mean to be a bug asking all these questions, it's just hard finding documentation for non-aura components.

– BlondeSwan
8 hours ago













@BlondeSwan You have been helping me/us to learn/know all this! So equally thanks to you :)

– Jayant Das
8 hours ago





@BlondeSwan You have been helping me/us to learn/know all this! So equally thanks to you :)

– Jayant Das
8 hours ago




2




2





Thanks Jayant. Much appreciated

– Pranay Jaiswal
8 hours ago





Thanks Jayant. Much appreciated

– Pranay Jaiswal
8 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Salesforce Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f251270%2flog-to-console-in-a-lightning-web-component%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy