nuxt-community / laravel-echo-module

Laravel Echo for Nuxt 2
MIT License
86 stars 31 forks source link

TypeError: io is not a function #66

Closed pexch closed 2 years ago

pexch commented 2 years ago
> client.js?06a0:103 TypeError: io is not a function
> at SocketIoConnector.connect (echo.js?5638:1149)
> at new Connector (echo.js?5638:142)
> at SocketIoConnector.eval (echo.js?5638:111)
> at new SocketIoConnector (echo.js?5638:1130)
> at Echo.connect (echo.js?5638:1414)
> at new Echo (echo.js?5638:1388)
> at eval (echo.js?1380:19)
> at _callee2$ (index.js?f26e:83)
> at tryCatch (runtime.js?96cf:63)
> at Generator.invoke [as _invoke] (runtime.js?96cf:294)
buildModules: [
  '@nuxtjs/laravel-echo'
],

echo: {
  broadcaster: 'socket.io',
  host: 'http://127.0.0.1:6500',
},

Already ran,

npm install --save-dev @nuxtjs/laravel-echo npm install socket.io-client

huongnx-0984 commented 2 years ago

@flyingspoon You can try install socket.io-client version 3.1.3 to fix this

pexch commented 2 years ago

I believe it was resolved by using a different version of this laravel-echo-module, ended up coding my own version. But thanks for trying to help!

msgpix commented 1 year ago

I have a similar error:

TypeError: io is not a function
    connect echo.js:1190
    Connector echo.js:951
    _createSuperInternal echo.js:129
    SocketIoConnector echo.js:1171
    connect echo.js:1455
    Echo echo.js:1429
    NuxtJS 2
    Babel 36
    NuxtJS 3
    js app.js:59
    __webpack_require__ runtime.js:859
    fn runtime.js:151
    0 app.js:12263
    __webpack_require__ runtime.js:859
    checkDeferredModules runtime.js:46
    webpackJsonpCallback runtime.js:33
    <anonymous> app.js:1
client.js:102
    _callee$ NuxtJS
    Babel 8
    NuxtJS 2
    js app.js:59
    __webpack_require__ runtime.js:859
    fn runtime.js:151
    0 app.js:12263
    __webpack_require__ runtime.js:859
    checkDeferredModules runtime.js:46
    webpackJsonpCallback runtime.js:33
    <anonyme> app.js:1

Looking at the top of the trace, the pertaining code block is

  _createClass(SocketIoConnector, [{
    key: "connect",
    value: function connect() {
      var _this2 = this;

      var io = this.getSocketIO();
      this.socket = io(this.options.host, this.options);
      this.socket.on('reconnect', function () {
        Object.values(_this2.channels).forEach(function (channel) {
          channel.subscribe();
        });
      });
      return this.socket;
    }
    /**
     * Get socket.io module from global scope or options.
     */

  },

With console.log(io), just after the line var io = this.getSocketIO(); returning:

Object { io: Getter, connect: Getter, default: Getter, Manager: Getter, Socket: Getter, protocol: Getter, … }

Any hint would be warmly welcome.