Log to console in a Lightning Web Component
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
add a comment |
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
1
Surprisingly console.log() work in playground
– Pranay Jaiswal
9 hours ago
1
That must be the ESLint error. You can still useconsole.log()
or sayalert()
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
add a comment |
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
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
error console lightning-web-components
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 useconsole.log()
or sayalert()
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
add a comment |
1
Surprisingly console.log() work in playground
– Pranay Jaiswal
9 hours ago
1
That must be the ESLint error. You can still useconsole.log()
or sayalert()
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
add a comment |
1 Answer
1
active
oldest
votes
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
Option to disable the rules by right clicking on the alert
+1. Thanks. I tried same in Illuminated Cloud for LWC, it showedSUCCEEDED_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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
Option to disable the rules by right clicking on the alert
+1. Thanks. I tried same in Illuminated Cloud for LWC, it showedSUCCEEDED_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
add a comment |
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
Option to disable the rules by right clicking on the alert
+1. Thanks. I tried same in Illuminated Cloud for LWC, it showedSUCCEEDED_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
add a comment |
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
Option to disable the rules by right clicking on the alert
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
Option to disable the rules by right clicking on the alert
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 showedSUCCEEDED_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
add a comment |
+1. Thanks. I tried same in Illuminated Cloud for LWC, it showedSUCCEEDED_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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 sayalert()
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