2013-10-03 29 views
3

我有一個Yeoman webapp項目,我已經使用bower添加了socket.io-client當運行grunt構建時socket.io客戶端中斷

當我運行webapp grunt server時,一切正常。但是,當我與grunt build建立它,我得到以下錯誤:

Uncaught TypeError: Cannot call method 'push' of undefined 

通過Gruntfile.jsgenerateSourceMaps: true),使源地圖,我設法追查錯誤的socket.io.js來源:

/** 
* Add the transport to your public io.transports array. 
* 
* @api private 
*/ 

io.transports.push('websocket'); 

什麼可以使io.transports成爲undefined運行後grunt build

UPDATE:

也許值得一說的是我用RequireJS和它的配置是這樣的:

require.config({ 
    paths: { 
     jquery: '../bower_components/jquery/jquery', 
     // ... 
     // socket.io: Try the node server first 
     'socket.io': ['/socket.io/socket.io', '../bower_components/socket.io-client/dist/socket.io'], 
    }, 
    shim: { 
     // Export io object: https://gist.github.com/guerrerocarlos/3651490 
     'socket.io': { 
      exports: 'io' 
     } 
    } 
}); 

require(['jquery', 'socket.io'], function ($, io) { 
    'use strict'; 
    // ... 
}); 

回答

0

您應該只有在路徑中定義的socket.io客戶端:

paths: { 
    'jquery': '../bower_components/jquery/jquery', 
    'socket.io': '../bower_components/socket.io-client/dist/socket.io' 
}, 

此外,您不應該設置io參數(它是全局設置的)(或使用其他類似sio)

require(['jquery', 'socket.io'], function ($) { 
    'use strict'; 
    // ... 
});