-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when building for WebPack #2109
Comments
I am also not sure how to add the socket.io-client library into my client-side app to connect back to the server. I am trying to require it like so:
...and I get this error: I'm mostly a back-end guy so client-side javascript is not my strong suit. Update: |
@johnelliott : just do |
Nope. The reason why it did not work for me was that I was using a plugin to resolve Bower modules, which didn’t play entirely nice on nested require()s. So what I did was to change that factor. If you were using a plugin called something like „bower-webpack-plugin“ or alike, dump it. the actual solution is this: var bowerProvider = new webpack.ResolverPlugin([ It totally look awkward, agreed. But if you read it over a couple of time,s you will realize that it changes the way that modules are resolved, and hence required. If that still does not work, then you could use a module alias. Within the client, the debug library is loaded like so: var debug = require(„debug“)(…); // excuse the quoting, my mail client sucks. So you can add a module alias in your webpack.config.js: // Add the alias section into the resolve section of the config. If that still does not work, let me know. :) |
Are you using |
I was not. I switched to SocketCluster in the meantime since that worked.
|
so the best solution is? |
import IO from 'socket.io-client' should work fine with |
When I used it, I think I'd called out for the index.js file directly. But its quite a while ago...so i cant be certain. |
Think this could be closed. |
I am getting this error still, I don't think this should be closed just yet. |
I fixed this by uninstalling socket.io-client from npm and installing via bower |
I am having this same problem. I don't use bower. Is there another way? |
You can use an alias in your webpack config. |
I came across the same problem when updating to Solving this by adding resolve: {
alias: {
'socket.io-client': path.join( nodeRoot, 'socket.io-client', 'socket.io.js' )
}
},
module: {
noParse: [ /socket.io-client/ ]
} Anyone has a better solution? |
@faller what do we put for node root? like in the public directory or is that something from an HTML file? |
@kennetpostigo |
I was getting the same error too. I think I managed to realize what is happening.
This is a problem for webpack, since it is not supposed to be working with that directive, how it is possible to see here. |
I'm getting a number of socket.io webpack build issues as well.
I've modified my webpack config to include |
There seems to be several different issues here.. It seems I was able to bundle both the client and the server here, can anyone check that example please? |
I was getting this error with Webpack 2.2 and socket.io-client 1.7.2. I tried pretty much everything listed here and nothing worked. Eventually I stopped the errors by installing the debug module into node_modules, |
Closed by #2828. |
Hi, I would like to reopen this issue because it works like a charm for socket.io-client, but not for the server ! So I cannot bundle my NodeJS server using socket.io with Webpack ! I have to put socket.io in the "externals" of webpack along with the few libraries that doesn't work (including webpack itself) See these related issues in Webpack and Yargs : |
@rgranger This's an example on how to use package.json
webpack.config.js const path = require("path");
module.exports = {
entry: './server.js',
target: 'node',
output: {
path: __dirname,
filename: 'bundle.server.js'
},
module: {
loaders: [
{
test: /(\.md|\.map)$/,
loader: 'null-loader'
},
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.js$/,
exclude: '/node_modules/',
loader: "transform-loader?brfs"
}
]
}
}; server.js const server = require('http').createServer();
const io = require('socket.io')(server, {
// serveClient: false // do not serve the client file, in that case the brfs loader is not needed
});
const port = process.env.PORT || 3000;
io.on('connect', onConnect);
server.listen(port, () => console.log('server listening on port ' + port));
function onConnect(socket){
console.log('connect ' + socket.id);
socket.on('disconnect', () => console.log('disconnect ' + socket.id));
} A sample Webpack build for the server : https://github.com/socketio/socket.io/tree/master/examples/webpack-build-server |
Thanks very much @Arbaoui-Mehdi, the key to get this fixed is to disable serving the client socket.js. |
@freemh you save my life bro |
When using Webpack v3, I just did ref: https://github.com/webpack-contrib/uglifyjs-webpack-plugin |
A while ago, I had realized that there is an error when trying to use
socket.io-client
within a WebPack module. It turns out, that "dist/debug.js" can not be located. I did a little bit of unixy research:Conclusion: The
dist
folder must be a virtual folder that is used during the Browserify process... Now, how exactly do I get rid of that? It's really heavy-lifting torequire("socket.io-client/socket.io")
although there already IS a system that knows commonJS.With heavy-lifting, I mean that adding the SIO client is ~350KB... A fix would be pretty awesome.
The text was updated successfully, but these errors were encountered: