24

I'm basically a beginner with JavaScript. I've installed brackets and currently playing around with variables and functions. All the outputs work fine in the console, however I keep getting this error in the editor. https://i.imgur.com/SExglwR.png

How do I go about fixing this?

Claies
  • 21,481
  • 3
  • 49
  • 75
Riddick
  • 253
  • 1
  • 2
  • 5
  • 1
    Possible duplicate of [Console.log error in Brackets](https://stackoverflow.com/questions/48124988/console-log-error-in-brackets) – Phil Ross Aug 19 '18 at 15:49

6 Answers6

55

The no-undef rule looks out for undefined variable, without any initial assumption on the environment and the global variables (console for instance).

You can specify that you are in an environment where console indeed exists, by adding browser and/or node envs in your .eslintrc:

  env: {
    browser: true,
    node: true,
  },

More info in the rule doc

Amaury Liet
  • 7,261
  • 1
  • 14
  • 21
  • Thanks! Although I don't want to commit any `console.log`'s in the app, it's nice to at least not have the error saying "console is undefined" while debugging small things. – dabyland Apr 23 '19 at 14:54
5

I assume it's coming from no-console rule, which disallows calls to methods of the console object.

In JavaScript that is designed to be executed in the browser, it’s considered a best practice to avoid using methods on console. Such messages are considered to be for debugging purposes and therefore not suitable to ship to the client. In general, calls using console should be stripped before being pushed to production.

Examples of correct code for this rule:

/*eslint no-console: "error"*/

// custom console Console.log("Hello world!");

As a solution, you can add this to your set of rules in .eslintrc

rules: {
    'no-console': 'off'
}
ummahusla
  • 1,889
  • 3
  • 24
  • 41
4

Since you have it as a Capitol C, I would guess that the editor thinks you're looking for a function or class. Try lowering it from Console.log() to console.log("john won...") and see if that works.

S.S.
  • 506
  • 2
  • 15
3

This one was driving me crazy as well. You can edit Brackets' config JSON. It will remove the error icon from the left gutter:

{
  "brackets-eslint.gutterMarks": false
}

Reference: https://github.com/brackets-userland/brackets-eslint/blob/master/README.md

nemanja
  • 564
  • 3
  • 14
3

just to have comment:
/*global console*/

as the first line of your .js file, and then have:
// eslint-disable-line no-console

at the line of the console.log("");

this will make the error go away!

Marius
  • 54,363
  • 28
  • 121
  • 143
  • 1
    or you can add these two lines to disable it completely in the whole .js file: /*global console*/ /* eslint no-console: "off" */ – Yunjun Wang Aug 20 '18 at 14:21
0

Deleting and recreating the .eslintrc file fixed this issue for me.