Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io is not a function #9

Open
standfv opened this issue Sep 29, 2023 · 12 comments
Open

io is not a function #9

standfv opened this issue Sep 29, 2023 · 12 comments

Comments

@standfv
Copy link

standfv commented Sep 29, 2023

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

@pavlienko
Copy link

have the same problem

@huangbh1024
Copy link

onMounted(() => {
	const io = useIO();
	const socket = io("http://127.0.0.1:7001/onlineCount");
});

is useful to me

@wobsoriano
Copy link
Owner

wobsoriano commented Dec 6, 2023

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
Copy link
Owner

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

@BayBreezy
Copy link

@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
Copy link
Owner

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

@BayBreezy
Copy link

@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
Copy link
Owner

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

@BayBreezy
Copy link

@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
Copy link

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

@Donny2333
Copy link

Donny2333 commented Dec 21, 2023

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants