14

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.

4
  • 1
    Surprisingly console.log() work in playground Feb 21, 2019 at 21:42
  • 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
    Feb 21, 2019 at 21:44
  • @JayantDas anything to supress linter error? Feb 21, 2019 at 21:48
  • 1
    @PranayJaiswal Looks like there's one for such cases.
    – Jayant Das
    Feb 21, 2019 at 21:54

1 Answer 1

20

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.

Your options are:

  1. Just ignore those warnings

  2. You can choose to suppress those warnings by right clicking on those to suppress either for that particular line or whole file. It though introduces following comments in your file.

    If you choose for whole file, the following is added in your file

    /* eslint-disable no-console */
    

    If you choose for specific line, the following is added before every such line

    // eslint-disable-next-line no-console
    
  3. By editing the .eslintrc.json available in your project by adding the below rules. This way you don't have to address individual files. (My preferred way)

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

Console showing errors

enter image description here

3
  • +1. Thanks. I tried same in Illuminated Cloud for LWC, it showed SUCCEEDED_PARTIAL Feb 21, 2019 at 21:54
  • 2
    @PranayJaiswal I updated my answer to include how to add the rules in .eslintrc.json in VS Code.
    – Jayant Das
    Feb 21, 2019 at 22:00
  • 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
    Feb 21, 2019 at 22:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .