question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: How to load Socket.io-client and other libraries that only support require?

See original GitHub issue

Sorry in advance for opening this as an issue but trying to get my head around all the new changes that are happening within vue 3 and their libraries within vite.

For 2-3 days now I’ve been struggling to import a ‘smarter’ library (like socket.io-client) than a simple ws wrapper or native web-sockets and whatever I try throw errors of ‘default’ is not been exported by these libraries. I realised that any library without support of ES6 import is not supported. Also tried vue & vue-next implementations of web-socket libraries but without any luck.

Can someone please explain with a few words how and if possible to overpass this problem within vite?

I have a simple vite codesandbox; if you can use it please to explain: https://codesandbox.io/s/vite-tailwind-starter-04mrv?file=/src/main.js

Many Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
johnpypcommented, Feb 24, 2021

I fixed it with:

  resolve: {
    alias: {
      "socket.io-client": "socket.io-client/dist/socket.io.js",
    },
  },

in vite.config.js

Still not ideal, but better than having to import from a different path in code.

2reactions
derappeltcommented, Feb 17, 2021

import socket from "socket.io-client/dist/socket.io.js"; worked for me. Sadly this breaks IntelliSense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Where is the socket.io client library? - node.js - Stack Overflow
The best way I have found to do this is to use bower. bower install socket.io-client --save. and include the following in your...
Read more >
Introduction | Socket.IO
IO is a library that enables low-latency, bidirectional and event-based communication between a client and a server.
Read more >
Client Installation | Socket.IO
IO server exposes a client bundle at /socket.io/socket.io.js . ... If you don't need this (see other options below), you can disable the ......
Read more >
Client Initialization | Socket.IO
Once you have installed the Socket.IO client library, you can now init the client. The complete list of options can be found below....
Read more >
How To Create a Real-Time App with Socket.IO, Angular, and ...
First, open your terminal and create a new project directory that will hold both our server and client code: mkdir socket-example ... Next,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found