Socket.io-client: I want use ES6 import in browser side js

Created on 4 Apr 2018  ·  3Comments  ·  Source: socketio/socket.io-client

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

You want to:

  • [ ] report a bug
  • [x] 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)

Most helpful comment

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!

All 3 comments

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.

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.

Was this page helpful?
0 / 5 - 0 ratings