wobsoriano / nuxt3-socket.io

Nuxt 3 and Socket.io integration.
59 stars 9 forks source link

io is not a function and _nuxt3Socket.defineIOHandler is not a function #5

Closed Elektronenhirn108 closed 1 year ago

Elektronenhirn108 commented 1 year ago

Hello,

I try to use this module, but I don't understand how to properly set it up based on the README.

I added nuxt3-socket.io to the modules and added

socket: {
    // JSON serializable options only.
    // options object to pass when instantiating socket server.
    serverOptions: {}
  } 

to my config. I also added the client example to a page. I had to remove const socket2 = io('http://localhost:3069') as it throws the error io is not a function. After that, the socket connects. Just for my understanding: this example connects to a default server socket that is included, running on the same port as the page? socket2 would be to connect to a different socket on a custom port & url?

If I try to customise the default server socket by creating the file /server/socket/test.ts with the example from the README, I get the following error when starting nuxt: ERROR [unhandledRejection] (0 , _nuxt3Socket.defineIOHandler) is not a function What did I do wrong in both cases?

It would be great if you can point me in the right direction.

mariusbolik commented 1 year ago

Thank you for this helpful Nuxt Module @wobsoriano! I really appreciate your work!

Sadly, I get the same Error using Node v18 and Nuxt v3.2.3. The interesting thing is that it works after I built and deployed the app using yarn build, but it doesn't work on the vite dev server using yarn dev.

Regards, Marius

wobsoriano commented 1 year ago

Fixed in https://github.com/wobsoriano/nuxt3-socket.io/pull/7