triniwiz / nativescript-socketio

Socket.IO for nativescript
Apache License 2.0
71 stars 31 forks source link

FeathersJS Socket.IO and net module #95

Open soullivaneuh opened 4 years ago

soullivaneuh commented 4 years ago

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

Import Feathers socket io client on one of your pages:

import socketio from '@feathersjs/socketio-client';

And run tns build android

You will get this error:

ERROR in ../node_modules/debug/src/node.js
Module not found: Error: Can't resolve 'net' in '/home/sullivan/p/github.com/soullivaneuh/svelte-native-test/node_modules/debug/src'
 @ ../node_modules/debug/src/node.js 193:16-30
 @ ../node_modules/debug/src/index.js
 @ ../node_modules/@feathersjs/transport-commons/lib/client.js
 @ ../node_modules/@feathersjs/transport-commons/client.js
 @ ../node_modules/@feathersjs/socketio-client/lib/index.js
 @ ./App.svelte
 @ ./app.ts
Executing webpack failed with exit code 2.

It's maybe FeathersJS related only, but I'm not sure and would like to know what you, native expert, thing about this issue.

Is there any code involved?

Here is a PR coming from a fresh svelte-native template: https://github.com/soullivaneuh/svelte-native-test/pull/2

soullivaneuh commented 4 years ago

If I install the net package and run tns run android (not build), now I get:

System.err: TypeError: Cannot read property 'env' of undefined
System.err:     at com.tns.Runtime.runModule(Native Method)
System.err:     at com.tns.Runtime.runModule(Runtime.java:674)
System.err:     at com.tns.Runtime.run(Runtime.java:666)
System.err:     at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
System.err:     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5740)
System.err:     ... 8 more

And the error is gone if I remove the import.

I'm not sure I have to install the net module by the way, I don't have to on web dev.

soullivaneuh commented 4 years ago

I also opened https://github.com/feathersjs/feathers/issues/1843, I'm not very sure what should be fixed here.

marshallswain commented 4 years ago

@soullivaneuh did the suggested fix resolve your issue?

I think it would be something like this:

import feathers from '@feathersjs/client'
import feathersSocketIO from '@feathersjs/socketio-client'

var SocketIO = require('nativescript-socketio').SocketIO;
var socket = new SocketIO('http://localhost:3030', { transports: ['websocket'] })

// let hasConnectedOnce = false
const feathersClient = feathers()
  .configure(feathersSocketIO(socket))