-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Avoid using debug
module and other node builtins in client library
#1188
Comments
Hi! I'm not familiar with Rollup, is it possible to exclude a library from a build? (like we did here with webpack) |
Thanks for the tip! I did some more experiments, but replacing debug did not work. It also looks for
Also tried using
Edit: Sorry realise cannot just import the dist (its a webpack build!). Rollup is a much simpler package manager (I like it much more than webpack). Will be great if you can build a browser friendly module that can be built via imports or commonjs without hacks. |
I also am running into this issue. |
For anyone still running into this issue (like me today), make sure to use the option Excluding the debug module like in the slim webpack build mentioned above does still reduce the bundle size. |
Added in the documentation here: https://socket.io/docs/v4/client-with-bundlers/#browser-1 |
See also: socketio/engine.io-client@00d7e7d Related: - #1188 - #1378
I am using this but still no luck, the xmlhttprequest-ssl imports 'url', 'http', and 'https' in the corresponding bundled file (I do preserveModules: true and I use esm format). I tried with rollup-plugin-polyfill-node but no luck. |
One workaround I've found is to use browserify for the entire socket.io-client module and then use an alias in rollup to point to the browserified module. You must do first: npx browserify -r socket.io-client -t [ babelify --presets [ @babel/preset-env ] ] -o module.browserified.js For this you must first install browserify, babelify and @babel/preset-env. Then you must manually edit the output (module.browserified.js). It must look like this: var require=....
const { io } = require("socket.io-client");
export { io }; The parts I've added is the Finally, in your rollup config file you do: plugins: [
alias({
entries: [
{
find: "socket.io-client",
replacement: path.resolve(__dirname, "module.browserified.js"),
},
]
})
] and for import { fileURLToPath } from "url";
import path from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename); I hope this can help anyone with the same problem as me and googling about it. |
Note: for support questions, please use one of these channels: stackoverflow or slack
You want to:
Current behaviour
Use
socket-io.client
in an app and build it with rollupJS file
Build with rollup
Steps to reproduce (if the current behaviour is a bug)
See above
Expected behaviour
Should be include client library easily without nodejs builtins
Setup
Other information (e.g. stacktraces, related issues, suggestions how to fix)
Client libraries should be dependent only on browser API.
Using nodejs builtins (debug) creates "dependency hell". I had to include socket.io-client separately with the
<script>
tag finally.The text was updated successfully, but these errors were encountered: