我有一个 Yeomanwebapp
项目,我在其中添加socket.io-client
了bower
.
当我使用grunt server
. 但是当我用 构建它时grunt build
,我收到以下错误:
Uncaught TypeError: Cannot call method 'push' of undefined
Gruntfile.js
通过在( )中启用源映射generateSourceMaps: true
,我设法找到了错误的来源socket.io.js
:
/**
* Add the transport to your public io.transports array.
*
* @api private
*/
io.transports.push('websocket');
运行后会导致什么io.transports
变得未定义grunt build
?
更新:
可能值得一提的是,我使用了 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';
// ...
});