wobsoriano / nuxt3-socket.io

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

io is not a function #9

Open standfv opened 1 year ago

standfv commented 1 year ago

My issues: io is not a function. When used custom. const io = useIO() const socket2 = io('http://localhost:3069')

pavlienko commented 1 year ago

have the same problem

huangbh1024 commented 1 year ago
onMounted(() => {
    const io = useIO();
    const socket = io("http://127.0.0.1:7001/onlineCount");
});

is useful to me

wobsoriano commented 10 months ago

I have published a new version. This does not fix it but uses the latest Nuxt version.

For the meantime, you can do what @huangbh1024 did, or

const { $io } = useNuxtApp()

const connected = ref(false)

onMounted(() => {
  const socket = $io('http://localhost:3069/');

  socket.on('connect', () => {
    connected.value = socket.connected
  })

  socket.on('disconnect', () => {
    connected.value = socket.connected
  })
})
wobsoriano commented 10 months ago

I'll deprecate this feature soon in favor of this.

BayBreezy commented 10 months ago

@wobsoriano Is there a production version of this working? I get this error when I run build followed by node .output/server/index.mjs

$ node .output/server/index.mjs 
node:internal/errors:496
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
    at new NodeError (node:internal/errors:405:5)
    at getPathFromURLWin32 (node:internal/url:1407:11)
    at Object.fileURLToPath (node:internal/url:1437:22)
    at file:///C:/Users/behon/Desktop/dev/nuxt-with-sockets-test/.output/server/chunks/nitro/node-server.mjs:5274:32
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25) {
  code: 'ERR_INVALID_FILE_URL_PATH'
}

Node.js v18.18.1
wobsoriano commented 10 months ago

@BayBreezy looks like I have to test it on windows 🫣

BayBreezy commented 10 months ago

@wobsoriano oh ok cool.. Would love if this worked in production lol. Let me know what you find when you get the time. Thanks 🙏🏽

wobsoriano commented 10 months ago

@BayBreezy thanks for confirming that it's not working in production build on windows!

BayBreezy commented 10 months ago

@wobsoriano I can confirm that the built version works on a mac 👍🏽

When deployed to Netlify, it does not work. ❌

When deployed on Ubuntu Server, it works fine. ✅

When deployed behind nginx it also works fine. ✅

Sadly I don't have a paid heroku account to test it on

I have not stress tested it yet but the few emits and listeners work great. Thanks for the module

BayBreezy commented 10 months ago

Confirming that it works on render.com too Live link: https://nuxt3-chat-render.onrender.com/

Donny2333 commented 10 months ago

@BayBreezy looks like I have to test it on windows 🫣

I get this error message when run nuxt after build it.

TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
    at new NodeError (node:internal/errors:387:5)
    at getPathFromURLWin32 (node:internal/url:1406:11)
    at Object.fileURLToPath (node:internal/url:1436:22)
    at file:///H:/DataFabric/jupiter/admin/.output/server/chunks/nitro/node-server.mjs:6717:32
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12) {
  code: 'ERR_INVALID_FILE_URL_PATH'
}
felixrydberg commented 9 months ago

@Donny2333 Were you able to get yours working? Having the same issue on windows still.