Skip to content
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

Closed
1 of 2 tasks
gtk2k opened this issue Apr 4, 2018 · 6 comments
Closed
1 of 2 tasks

I want use ES6 import in browser side js #1198

gtk2k opened this issue Apr 4, 2018 · 6 comments
Labels
enhancement New feature or request
Milestone

Comments

@gtk2k
Copy link

gtk2k commented Apr 4, 2018

Note: for support questions, please use one of these channels: stackoverflow or slack

You want to:

  • report a bug
  • request a feature

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

  • OS:
  • browser:
  • socket.io version:

Other information (e.g. stacktraces, related issues, suggestions how to fix)

@jcc10
Copy link

jcc10 commented May 16, 2019

I would like to add that the following on the README.md

<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.

@zevero
Copy link

zevero commented Jun 29, 2020

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!

@jcc10
Copy link

jcc10 commented Jul 19, 2020

just adding on that .mjs is the preferred file type for ES6 modules.

@chase-moskal
Copy link

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 require, and the whole thing fails

#1378 is a possible duplicate

@darrachequesne
Copy link
Member

@chase-moskal thanks for the heads-up! I'm digging into this.

darrachequesne added a commit that referenced this issue Oct 13, 2021
This change allows us to:

- reduce the size of the bundle
- provide an ESM bundle (for usage in <script type="module">)

Related: #1198
darrachequesne added a commit to socketio/socket.io that referenced this issue Oct 13, 2021
@darrachequesne
Copy link
Member

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

@darrachequesne darrachequesne added this to the 4.3.0 milestone Oct 15, 2021
@darrachequesne darrachequesne added the enhancement New feature or request label Oct 15, 2021
sunrise30 added a commit to sunrise30/socket.io-client that referenced this issue Jan 8, 2022
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
dzad pushed a commit to dzad/socket.io that referenced this issue May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants