最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - xo lint error: `document` is not defined - Stack Overflow

programmeradmin2浏览0评论

I've been a long time user of Standard, and now that I'm working on a new project, I've been asked to start writing semicolons.

I'm trying to use both xo, Babel and React, but I keep getting an error when I try to lint my code: document is not defined. no-undef

I've tried adding an env option to the xo field in my package.json file, but no success.

My xo config:

"xo": {
  "esnext": true,
  "extends": "xo-react",
  "space": true,
  "rules": {
    "react/jsx-space-before-closing": 0
  } 
}

I've been a long time user of Standard, and now that I'm working on a new project, I've been asked to start writing semicolons.

I'm trying to use both xo, Babel and React, but I keep getting an error when I try to lint my code: document is not defined. no-undef

I've tried adding an env option to the xo field in my package.json file, but no success.

My xo config:

"xo": {
  "esnext": true,
  "extends": "xo-react",
  "space": true,
  "rules": {
    "react/jsx-space-before-closing": 0
  } 
}
Share Improve this question asked Oct 4, 2016 at 6:58 Jonathan OhayonJonathan Ohayon 1113 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

It is cumbersome to specify linting options such as /** global document **/ and edit a configuration file every time you use a global.

This error can be suppressed by using --env=browser option:

xo --env=browser [<file|glob> ...]

Note: Same problem es with Node.js, where the linter will plain that require and friends are not defined. The switch has to change to --env=node in that case.

However, XO defaults the env to node, therefore this will not be a problem in most cases. You will need multiple environments if your project contains both client and server files. in that case, --env switch can be set multiple times:

xo --env=browser --env=node [<file|glob> ...]

You have to define globals in ESLint. There are two ways to acplish this, firstly as a ment in your code:

/* global document */

Or you can configure in configuration file like so:

{ "globals": { "var1": true, "var2": false } }

See the ESLint docs for more

发布评论

评论列表(0)

  1. 暂无评论