A função usa o caminho relativo para verificar o socket.io-client. No entanto, se eu usar o webpack para agrupar um aplicativo nodejs que usa o webpack. Este se tornará o caminho relativo para socket.io-client em node_modules.
O nó em execução retornará um erro:
Erro: Não é possível encontrar o módulo "."
Observação : a melhor maneira de obter uma resposta rápida é fornecer um caso de teste com falha, bifurcando o seguinte violino, por exemplo.
O código compilado no pacote torna-se:
Server.prototype.serveClient = function(v){
if (!arguments.length) return this._serveClient;
this._serveClient = v;
var resolvePath = function(file){
var filepath = path.resolve(__dirname, './../../', file);
if (exists(filepath)) {
return filepath;
}
return /*require.resolve*/(!(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()));
};
if (v && !clientSource) {
clientSource = read(resolvePath( 'socket.io-client/dist/socket.io.js'), 'utf-8');
try {
clientSourceMap = read(resolvePath( 'socket.io-client/dist/socket.io.js.map'), 'utf-8');
} catch(err) {
debug('could not load sourcemap file');
}
}
return this;
};
O pacote deve ser compilado com o webpack perfeitamente e funcionar sem problemas.
o mesmo problema
Tente desabilitar socket.io's _serving client files_ feat.
const io = require('socket.io')(httpServer, { serveClient: false })
Não é o ideal, mas pelo menos o pacote funciona.
Acho que é o mesmo erro, consigo no tempo de execução usando o webpack
Error: Cannot find module 'socket.io-client/dist/socket.io.js'
Eu não uso socket.io
self, mas é uma dependência de androidjs
se eu usar raw-loader
pelo patch a seguir, ele funciona
diff --git a/node_modules/socket.io/lib/index.js b/node_modules/socket.io/lib/index.js
index 5287e4e..9ee4577
--- a/node_modules/socket.io/lib/index.js
+++ b/node_modules/socket.io/lib/index.js
@@ -113,9 +113,9 @@ Server.prototype.serveClient = function(v){
return require.resolve(file);
};
if (v && !clientSource) {
- clientSource = read(resolvePath( 'socket.io-client/dist/socket.io.js'), 'utf-8');
+ clientSource = require( 'raw-loader!socket.io-client/dist/socket.io.js');
try {
- clientSourceMap = read(resolvePath( 'socket.io-client/dist/socket.io.js.map'), 'utf-8');
+ clientSourceMap = require( 'raw-loader!socket.io-client/dist/socket.io.js.map');
} catch(err) {
debug('could not load sourcemap file');
}
Obrigado, isso funcionou para mim.
Comentários muito úteis
Tente desabilitar socket.io's _serving client files_ feat.
const io = require('socket.io')(httpServer, { serveClient: false })
Não é o ideal, mas pelo menos o pacote funciona.