简体   繁体   English

Yeoman(bower,grunt) - 'SockJS'没有定义

[英]Yeoman (bower,grunt) - 'SockJS' is not defined

I am trying to manage a javascript frontend application with yeoman. 我正在尝试用自耕农管理javascript前端应用程序。 I don't have any yeoman experience. 我没有任何自耕农的经历。 While running grunt command I am getting this error: 在运行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);

I have defined sock js dependency in bower.json : 我在bower.json中定义了sock js依赖:

{
  "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. 和bower install命令运行没有问题,它下载所有依赖项,包括sockjs。

This is the file that the grunt command complains about : 这是grunt命令抱怨的文件:

'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? 为了让SockJS得到认可,我该怎么做?

JSHint thinks SockJS is undefined because it cannot find it in your script; JSHint认为SockJS未定义,因为它无法在您的脚本中找到它; even if you have loaded it in through the browser! 即使您已通过浏览器加载它! To fix this behaviour, add this to the JSHint config in your Gruntfile: 要解决此问题,请将其添加到Gruntfile中的JSHint配置中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM