socket.io-client@0.9.7与typescript和webpack2导入错误


ERROR in ./~/socket.io-client/bin/builder.js
Module not found: Error: Can't resolve 'fs' in 'E:workbrickman2node_modulessocket.io-clientbin'
@ ./~/socket.io-client/bin/builder.js 11:9-22
@ ./~/socket.io-client/lib/io.js
@ ./src/services/pusher.ts
@ multi main
ERROR in ./~/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Error: Can't resolve 'fs' in 'E:workbrickman2node_modulesxmlhttprequestlib'
@ ./~/xmlhttprequest/lib/XMLHttpRequest.js 16:9-22
@ ./~/socket.io-client/lib/util.js
@ ./~/socket.io-client/lib/io.js
@ ./src/services/pusher.ts
@ multi main
ERROR in ./~/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Error: Can't resolve 'child_process' in 'E:workbrickman2node_modulesxmlhttprequestlib'
@ ./~/xmlhttprequest/lib/XMLHttpRequest.js 15:12-36
@ ./~/socket.io-client/lib/util.js
@ ./~/socket.io-client/lib/io.js
@ ./src/services/pusher.ts
@ multi main

我搜索与谷歌和github的问题,但没有人为我工作。

socket.io-client@0.9.7是旧版本,但无法更新。因为插座。服务器的IO版本是0.9.7,不能更改。如果我更新客户端将无法连接服务器

我遇到了同样的问题,并找到了下一个解决方案-替换要求socket-io。客户端为它的捆绑版本。

ES5版本

//var io = require('socket.io-client');
var io = require('socket.io-client/dist/socket.io.js'); //worked solution

ES6版本

//import io from 'socket.io-client';
import io from 'socket.io-client/dist/socket.io.js'; //worked solution

最新更新