Sublime Linter / ReferenceError:窗口未定义?

时间:2013-07-31 04:06:23

标签: javascript sublimetext2 jshint sublimelinter

我知道这是一个非常基本的问题,但很奇怪我无法工作,花了好几个小时后,我真的需要帮助。

  • OSX 10.8.4
  • sublime Text 2 Version 2.0.2 Build 2221
  • node v0.10.15
  • jshint v2.1.7

实际上,我为此清理安装了崇高的Text 2;只安装 Sublime Package Control

首先,我准备了 foo.js 代码:

function x(a, b)
{
    return a + b

res = x(10, 20)
console.log("res = " + res);

结果:

$ jshint foo.js                                       
foo.js: line 3, col 17, Missing semicolon.
foo.js: line 6, col 16, Missing semicolon.
foo.js: line 2, col 1, Unmatched '{'.

3 errors

因此, jshint 目前为止进行了简单测试。

我尝试了很多东西让它与Sublime Linter一起工作,但没有成功,我清理安装了sublime应用程序,然后按照教程视频:

https://tutsplus.com/lesson/sublime-linter/

看起来很简单,Sublime Linter显然已成功安装,自述文件显示为00:30的视频节目,但在我的情况下,保存或任何从不触发任何内容。

好吧,我完全迷失了。请指教。感谢。

更新

我注意到sublimeText控制台显示错误!

Traceback (most recent call last):
  File "./SublimeLinter.py", line 431, in _update_view
  File "./SublimeLinter.py", line 143, in run_once
  File "./sublimelinter/modules/base_linter.py", line 291, in run
  File "./sublimelinter/modules/javascript.py", line 72, in parse_errors
ValueError: Error from jshint: /Users/ken/Library/Application Support/Sublime Text 2/Packages/SublimeLinter/sublimelinter/modules/libs/jshint/jshint.js:7881
})(window)
   ^
ReferenceError: window is not defined
    at Object.require.util (/Users/ken/Library/Application Support/Sublime Text 2/Packages/SublimeLinter/sublimelinter/modules/libs/jshint/jshint.js:7881:4)

编辑: 好吧,这似乎是错误,我应该先在那里检查..

https://github.com/SublimeLinter/SublimeLinter/issues

2 个答案:

答案 0 :(得分:0)

目前有一种解决方法:

此修补程序是 - 在Linux安装中 - 添加

  

global.window = {};

到文件顶部

  

~/.config/sublime-text-2/Packages/SublimeLinter/sublimelinter/modules/libs/jshint/jshint.js

对于Windows或OS / X安装,您需要找到Sublime Text包配置的位置。

答案 1 :(得分:0)

对于仍然收到此错误的用户,请修改JSHint configuration file并添加以下选项:

"jshint_options": {
  "undef": true,
  "unused": true,
  "browser": true, /* Defines DOM globals such as window, navigator, FileReader, etc. */
  "jquery": true, /* OPTIONAL: globals exposed by jQuery */
  "devel": true,  /* OPTIONAL: globals such as debugging, alert  */
  "globals": {    /* OPTIONAL: set others that aren't predefined by JSHint */ 
    "Modernizr": true
  }
}

详细了解pre-defined JSHint global variables