Cloud Stack Ninja

I'd like to import the socket.io-client library as ES6 import.


Using following import syntax:

import io from 'socket.io-client.js';

returns the error Requested module does not provide an export".

error 1


As a workaround I was using following code to create a module from the socket.io code:

in socket.io.mjs

// import 'https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js';
import './socket.io-client.js';
export default globalThis.io;

But the error message this time says "Cannot set property 'io' of undefined."

error 2


So to my question - Is there any possibility to import socket.io on the client-browser side via ES6 imports?

Note that I'd really like to avoid using < script >-tags, loading the code myself or loading by require.js, browserify and co!



Read more here: https://stackoverflow.com/questions/64405808/use-socket-io-in-browser-via-es6-import

Content Attribution

This content was originally published by jns at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: