【问题标题】:Yeoman (bower,grunt) - 'SockJS' is not definedYeoman (bower,grunt) - 'SockJS' 未定义
【发布时间】:2013-10-06 15:15:48
【问题描述】:

我正在尝试使用 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 被识别?

【问题讨论】:

    标签: javascript gruntjs yeoman bower sockjs


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-14
      • 1970-01-01
      • 2016-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-11
      相关资源
      最近更新 更多