Eslint does not recognize private field declaration using nodejs 12

The upvoted answer is a little out of date, the babel-eslint package has changed, also, you need to make sure you have Babel configured too, in my case I was on a server, so it wasn't.

I blogged about the solution here: https://dev.to/griffadev/setting-up-eslint-to-work-with-new-or-proposed-javascript-features-such-as-private-class-fields-5fm7

TL;DR:

npm i eslint @babel/core @babel/eslint-parser @babel/preset-env -D

Example .eslintrc

{
    "env": {
        "browser": true,
        "es2021": true,
        "node": true
    },
    "extends": "eslint:recommended",
    "parser": "@babel/eslint-parser",
    "parserOptions": {
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "rules": {
    }
}

Configure .babelrc

{
    "presets": [
      ["@babel/preset-env",
      {
        "shippedProposals": true
      }]
    ]
}

If you are using Jest and you don't have a .babelrc configured already, it will start picking up this new file, this may be a problem. You can workaround this by renaming the .babelrc file to something else, and updating eslint config file:

"babelOptions": {
    "configFile": "./.babel-eslintrc"
 }


2021 Update: You do not need babel for this anymore!

You can simply update eslint to v8.0.0 and above.

See eslint release notes: https://eslint.org/blog/2021/10/eslint-v8.0.0-released#highlights

Make sure this is in your .eslintrc file or similar:

{
    "parserOptions": {
        "ecmaVersion": 13
    }
}

You can also just use latest instead of specifically version 13.