chrisguttandin / rxjs-broker

An RxJS message broker for WebRTC DataChannels and WebSockets.
MIT License
24 stars 4 forks source link

RxJS Imports in Incorrect Format for v7+ #303

Closed rc65 closed 2 years ago

rc65 commented 3 years ago

I'm trying to create a minimum working example of your timing-object and timing-provider libraries based off of this comment here: https://github.com/chrisguttandin/timing-provider/issues/15#issuecomment-798833213

I'm using a freshly made create-react-app project to do this, and trying to run npm start yields this message:

Failed to compile.

./node_modules/rxjs-broker/build/es2019/classes/data-channel-subject.js
Module not found: Can't resolve 'rxjs/internal/Subject' in '/Users/rossconyers/dev/testing123/node_modules/rxjs-broker/build/es2019/classes'

I believe it's because the imports in rxjs-broker project no longer work for versions of RxJS 7+, there's no rxjs-compat released for version 7+, and this project does not pin a version of RxJS for some reason.

Is this correct or am I misunderstanding the issue? My apologies if so, I'm not terribly experienced with npm.

chrisguttandin commented 3 years ago

Hi @rc65,

thanks for reporting this. Someone mentioned this error to me lately but since I couldn't reproduce it I thought it might be caused by a version mismatch somewhere in the dependency tree.

As far as I can tell rxjs/internal/Subject is still exposed although it's deprecated and I need to replace it in the long term.

In the short term my suspicion is that this is only problematic when transpiling to a certain type of JavaScript. The fact that I can't reproduce it but you can makes me believe that we transpile to a different version of JavaScript or use different bundlers.

Could you try manually replacing the import from 'rxjs/internal/Subject' to 'rxjs/internal/Subject.js'? Hopefully that fixes the issue for now.

rc65 commented 3 years ago

Hi Chris,

Thanks for the response.

That makes sense. I seem to have other transpilation errors now like this one:

Failed to compile.

./node_modules/rxjs-interop/dist/esm/to-observer.js 14:36
Module parse failed: Unexpected token (14:36)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|
|     return {
>       complete: (observer.complete ?? noop).bind(observer),
|       error: (observer.error ?? rethrow).bind(observer),
|       next: (observer.next ?? noop).bind(observer)

So I think fixing all these little things might be too big an issue. I'll investigate how to setup webpack and babel myself instead of using create-react-app. Maybe that way I can specify the version of ECMAScript that I want to transpile to? It's been a while since I've worked with the JavaScript toolchains 😄

Thanks for the pointers.

rc65 commented 3 years ago

If it's any use, I also get this when trying to install the dependencies:

➜ npm i timing-object timing-provider timingsrc timing-provider-server
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: backoff-rxjs@6.5.7
npm WARN Found: rxjs@7.4.0
npm WARN node_modules/rxjs
npm WARN   rxjs@"^7.4.0" from timing-provider@5.0.8
npm WARN   node_modules/timing-provider
npm WARN     timing-provider@"*" from the root project
npm WARN   3 more (rxjs-broker, rxjs-connector, rxjs-etc)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer rxjs@"^6.5.5" from backoff-rxjs@6.5.7
npm WARN node_modules/backoff-rxjs
npm WARN   backoff-rxjs@"^6.5.7" from timing-provider@5.0.8
npm WARN   node_modules/timing-provider
npm WARN
npm WARN Conflicting peer dependency: rxjs@6.6.7
npm WARN node_modules/rxjs
npm WARN   peer rxjs@"^6.5.5" from backoff-rxjs@6.5.7
npm WARN   node_modules/backoff-rxjs
npm WARN     backoff-rxjs@"^6.5.7" from timing-provider@5.0.8
npm WARN     node_modules/timing-provider
rc65 commented 3 years ago

I got it all working eventually after creating the React project from scratch. I'm not sure what create-react-app was doing that messed it up so much.

I've uploaded the sample project to a repo here for others to see how to get started with React in case it's of any use: https://github.com/rc65/timingsrc-multidevice-example

It allows you to run a timing-provider-server on your computer and connect multiple devices on the same local network to test it out.

Thanks for all the libraries @chrisguttandin, seems to work really well on my local machine. 👍

chrisguttandin commented 2 years ago

Hi @rc65,

sorry for the long delay. As of recently the timing-provider package doesn't depend on this library anymore to simplify things a bit. Therefore I think it's okay to finally close this issue now.

Thanks a lot for making your sample project available.