Sails: The provided socket.io client (`io`) has already been augmented into a Sails socket SDK instance (it has `io.sails`)

Created on 25 May 2017  路  7Comments  路  Source: balderdashy/sails

Hi guys

I'm using Sails.js + Nuxt, but Im only using Sails.js for backend and Nuxt as middleware.
I have a problem, I follow the example for nuxt and websocket combine with basic usages of sails.io.js.

I have a problem:

Nuxt.js Error:

Error: The provided socket.io client (`io`) has already been augmented into a Sails socket SDK instance (it has `io.sails`).
    at SailsIOClient (C:\Users\user\Documents\sailsnuxt\node_modules\sails.io.js\sails.io.js:376:15)
    at Object.222 (plugins/socket-client.js:9:26)
    at __webpack_require__ (webpack:/webpack/bootstrap e43f81667f2018ddd90e:25:0)
    at Object.231 (2.server-bundle.js:480:84)
    at __webpack_require__ (webpack:/webpack/bootstrap e43f81667f2018ddd90e:25:0)
    at Object.214 (pages/noticias/index.vue:7:0)
    at __webpack_require__ (webpack:/webpack/bootstrap e43f81667f2018ddd90e:25:0)

I know what might be the problem, its probably because of this file sails-generate-sails.io.js\node_modules\sails.io.js-dist\sails.io.js, but I have had to install sails.io.js to use it in nuxt, so its show me this conflict.
If I uninstall sails.io.js, doesn't work import sailsIOClient from 'sails.io.js' and if I install it, generates error.

What do you suggest that I have to do?

Thanks

Most helpful comment

same error but unable to solve by using fortil's solution,
fixed as below.

import socketIOClient from 'socket.io-client';
import sailsIOClient from 'sails.io.js';
let io;
if (socketIOClient.sails) {
  io = socketIOClient;
} else {
  io = sailsIOClient(socketIOClient);
}

All 7 comments

Tree files; the plugin file socket-client.js (require in Nuxt), nuxt.config.js file where I show that sails.io.js is in vendor and SocketController file.
image

I already resolved it

@fortil: Can you explain how? I have the same error

@MitsuhaKitsune some guys only want solutions to solve their issues and they don't want to help others in case they find a way out.. i have the same problem too.. but mine with react-native.. same error!.

Hello @MitsuhaKitsune and @pepya2, I'm sorry for my answer late but this problem was once up on at time and I don't remember fine how I resolved it, I seeing in the logs of the repo some days after of this issue is this code.

import socketIOClient from 'socket.io-client'
import sailsIOClient from '~/node_modules/sails.io.js'
let io = {}
if (process.BROWSER_BUILD) {
  io = sailsIOClient(socketIOClient)
  io.sails.url = 'http://localhost:1337'
}
// const ioS = sailsIOClient(socketIOClient)

// ioS.sails.url = 'http://localhost:1337'

export default io

same error but unable to solve by using fortil's solution,
fixed as below.

import socketIOClient from 'socket.io-client';
import sailsIOClient from 'sails.io.js';
let io;
if (socketIOClient.sails) {
  io = socketIOClient;
} else {
  io = sailsIOClient(socketIOClient);
}

Solution (Worked for me)
The problem here is you are trying to generate another instance of socket in current component (by either importing socket-io or a module which is using it) but as it is already been imported in your "app.component.module" , (reason) ->It is throwing already augmented . You just have to look for the module that is trying to initiate socket again and remove it from your local module imports.
angular 8

Was this page helpful?
0 / 5 - 0 ratings