2

I'm using Reflect in my code. Problem is Eslint thinks its an undeclared variable. I'm getting this error:

eslint --config ./.eslintrc.json src

30:25  error  'Reflect' is not defined  no-undef
32:9   error  'Reflect' is not defined  no-undef
39:21  error  'Reflect' is not defined  no-undef
40:5   error  'Reflect' is not defined  no-undef

I have my .eslintrc file set to ECMAScript 2015:

"parserOptions": {
    "ecmaVersion": 2015,
    "sourceType": "module",
    "ecmaFeatures": {
      "globalReturn": true
    }
  }

Not sure why it's applying the no-undef rule to Reflect. All my code is typically ECMAScript 2015, nothing unusual.

Robert Biggs
  • 333
  • 2
  • 8

1 Answers1

3

In addition to setting the ecmaVersion, you need to tell it to include "es6" globals:

{
    "env": {
        "es6": true
    }
}

(You'll probably want others in there too, such as browser.)

More in Specifying Environments in the docs.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Yup, that fixed it. I was not expecting having to set es6 in two places: parserOptions and env. In fact, just removed "ecmaVersion": 2015 from parserOptions and left es6 in env. and it works. So I'm wondering why you would ever need the parserOptions setting. – Robert Biggs Oct 05 '18 at 09:27
  • @RobertBiggs - If you use the `es6` `env` setting, it sets `ecmaVersion` to `6` (`2015`). If you want to use later features (like property spread from ES2018), you'd want to set `ecmaVersion` to something higher. I think they're separated because some people transpile advanced syntax but don't use polyfills for new builtins. – T.J. Crowder Oct 05 '18 at 09:39