ES6 Express app, using socket.io in other backend files: 'Cannot access 'io' before initialization' #4829
-
In the simple repo linked below, one module works, but the other module throws an error. In the module that works, there is some delay (a cron function) before io is called. Things also work with a setInterval() function. In the module that does not work, io is employed with no delay, and I get the error 'Cannot access 'io' before initialization'. I have tried writing the non-working module as an async function ("await io"), but this does not work either.
https://github.com/respectabiggle/socket-test Imports
Works
Does not work
Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi! I think that's because you have a circular dependency in your code:
Could you please check? |
Beta Was this translation helpful? Give feedback.
-
Oh wow yes, you are right. Thank you for taking the trouble to read my thread!! I hope you have a great day. |
Beta Was this translation helpful? Give feedback.
Hi! I think that's because you have a circular dependency in your code:
Could you please check?