ESLint - "window" is not defined. How to allow global variables in package.json

chevin99 picture chevin99 · May 22, 2015 · Viewed 114.3k times · Source

I am assigning a property to the global window object, but when I run eslint, I get this:

"window" is not defined

I see this here in the eslint docs:

the following defines window as a global variable for code that should not trigger the rule being tested:

valid: [
  {
    code: "window.alert()",
    globals: [ "window" ]
  }
]

I've tried adding something like this to the package.json file to have eslint allow "window" as a global variable, but I must be doing something wrong. From the docs it seems like I might need to do something like this in a separate file, but is there a way to define some allowed global variables right in the package.json file?

Answer

Laoujin picture Laoujin · Sep 9, 2015

There is a builtin environment: browser that includes window.

Example .eslintrc.json:

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

More information: http://eslint.org/docs/user-guide/configuring.html#specifying-environments

Also see the package.json answer by chevin99 below.