سؤال

I am trying to manage a javascript frontend application with yeoman. I don't have any yeoman experience. While running grunt command I am getting this error:

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

I have defined sock js dependency in bower.json :

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

and bower install command runs without problems and it downloads all dependencies including sockjs.

This is the file that the grunt command complains about :

'use strict';

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

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

What do I have to do in order to make SockJS recognized?

هل كانت مفيدة؟

المحلول

JSHint thinks SockJS is undefined because it cannot find it in your script; even if you have loaded it in through the browser! To fix this behaviour, add this to the JSHint config in your Gruntfile:

jshint: {
    options: {
        // all of your other options...
        predef: ['SockJS']
    },
    files : ['path/to/main.js']
},
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top