javascript – Yeoman(bower,grunt) – ‘SockJS’没有定义

我正在尝试用自耕农管理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得到认可,我该怎么做?

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

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

转载注明原文:javascript – Yeoman(bower,grunt) – ‘SockJS’没有定义 - 代码日志