Yeoman(凉亭,咕噜声) - ' SockJS'没有定义

时间:2013-10-06 15:15:48

标签: javascript gruntjs yeoman bower sockjs

我正在尝试使用yeoman管理javascript前端应用程序。我没有任何自耕农的经历。运行grunt命令时出现此错误:

Running "jshint:all" (jshint) task
Linting app/scripts/services/stopmOverSockJs.js ...ERROR
[L7:C26] W117: 'SockJS' is not defined.
        var socket = new SockJS(url);

我在bower.json中定义了sock js依赖:

{
  "name": "web",
  "version": "0.0.0",
  "dependencies": {
      "sockjs": "~0.3.4",
      "angular": "~1.0.7",
...

和bower install命令运行没有问题,它会下载所有依赖项,包括sockjs。

这是grunt命令抱怨的文件:

'use strict';

angular.module('webApp').factory('sockJsHelper', function($rootScope) {

    function Handler(url) {
        var socket = new SockJS(url); //it complains about this line
.... 

为了让SockJS得到认可,我该怎么做?

1 个答案:

答案 0 :(得分:7)

JSHint认为SockJS未定义,因为它无法在您的脚本中找到它;即使您已通过浏览器加载它!要解决此问题,请将其添加到Gruntfile中的JSHint配置:

jshint: {
    options: {
        // all of your other options...
        predef: ['SockJS']
    },
    files : ['path/to/main.js']
},