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

时间:2016-11-09 06:10:43

标签: typescript socket.io webpack-2

ERROR in ./~/socket.io-client/bin/builder.js
Module not found: Error: Can't resolve 'fs' in 'E:\work\brickman2\node_modules\socket.io-client\bin'
@ ./~/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:\work\brickman2\node_modules\xmlhttprequest\lib'
@ ./~/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:\work\brickman2\node_modules\xmlhttprequest\lib'
@ ./~/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

我用google和github issus搜索过,但没有人为我工作。

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

1 个答案:

答案 0 :(得分:3)

我遇到了同样的问题并找到了下一个解决方案 - 需要socket-io.client来替换它的捆绑版本。

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