-
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
I want use ES6 import in browser side js #1198
Comments
I would like to add that the following on the <script src="/socket.io/socket.io.js"></script>
<script>
var socket = io('http://localhost');
socket.on('connect', function(){});
socket.on('event', function(data){});
socket.on('disconnect', function(){});
</script> // with ES6 import
import io from 'socket.io-client';
const socket = io('http://localhost'); Is misleading since it makes it look like you can use ES6 import on the client-side. Which you can't. |
I was fooled as well. I do not always want to use webpack or similar. ES6 imports are nothing new any more. Please make it work! Many projects have a dedicated *.module.js which can be imported! |
just adding on that .mjs is the preferred file type for ES6 modules. |
hello, i was very disappointed to see that socket.io doesn't actually support clientside es modules this is a significant pain the documentation seems to be under the false impression that socket.io does support clientside es modules, but when you try to load it, the browser chokes when it find that the wrapper.mjs merely re-exports a file which is actually using #1378 is a possible duplicate |
@chase-moskal thanks for the heads-up! I'm digging into this. |
This change allows us to: - reduce the size of the bundle - provide an ESM bundle (for usage in <script type="module">) Related: #1198
Done! An ESM bundle is now provided: <script type="module">
import { io } from "https://cdn.socket.io/4.3.0/socket.io.esm.min.js";
const socket = io();
socket.emit("hello", "world");
</script> Release notes: https://github.com/socketio/socket.io-client/releases/tag/4.3.0 |
This change allows us to: - reduce the size of the bundle - provide an ESM bundle (for usage in <script type="module">) Related: socketio/socket.io-client#1198
Note: for support questions, please use one of these channels: stackoverflow or slack
You want to:
Current behaviour
Steps to reproduce (if the current behaviour is a bug)
Note: the best way to get a quick answer is to provide a failing test case, by forking the following fiddle for example.
Expected behaviour
Setup
Other information (e.g. stacktraces, related issues, suggestions how to fix)
The text was updated successfully, but these errors were encountered: