Yeoman(bower,grunt)- 'SockJS'未定义

3

我正在尝试使用yeoman来管理JavaScript前端应用程序,但我没有任何yeoman经验。在运行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个回答

7

JSHint认为SockJS未定义,因为它在您的脚本中找不到它; 即使你通过浏览器加载了它! 要解决此问题,请将以下内容添加到Gruntfile中的JSHint配置中:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接