RobotWebTools / rclnodejs

Node.js version of ROS 2.0 client
https://docs.ros.org/en/humble/Concepts/Basic/About-Client-Libraries.html?highlight=rclnodejs#community-maintained
Apache License 2.0
319 stars 70 forks source link

Using rclnodejs in a react-app doesn't work #698

Closed sshmaxime closed 4 years ago

sshmaxime commented 4 years ago

Hello,

System: docker Base Image: Ubuntu 20.04 ROS: Foxy Node: 12.x LTS

I'm trying to create a ROS2 node using rclnodejs with Typescript inside a create-react-app but I'm having a warning when I launch the app.

./node_modules/rclnodejs/lib/interface_loader.js
Critical dependency: the request of a dependency is an expression

Do you have any ideas about what could cause this ?

sshmaxime commented 4 years ago

From what I understood, I cannot run rclnodejs on the client side because rclnodejs needs fs which CRA doesn't provide, can you guys confirm this ? Thanks :)

minggangw commented 4 years ago

CRA doesn't provide

What's CRA? Is it create-react-app?

The rclnodejs does depend on fs module and you could reference https://github.com/RobotWebTools/rclnodejs/blob/foxy-fitzroy/Dockerfile about the usage of docker.

sshmaxime commented 4 years ago

Yes sorry, CRA is create-react-app.

When I was importing import * as rclnodejs from 'rclnodejs' as follow in my typescript app, I was having this error TypeError: exists is not a function. Leading me to fs. Maybe one of rclnodejs dependencies use fs ?

minggangw commented 4 years ago

https://github.com/RobotWebTools/rclnodejs/blob/95729f9a3650547b372fa1dc2c37d3d7f1d85d82/rosidl_gen/index.js#L42-L43

rclnodejs uses it directly when generating JavaScript messages. If you have installed it, there should be no error reported I think.

sshmaxime commented 4 years ago

AFAIK react app does not allow the use of fs.

See https://github.com/facebook/create-react-app/issues/3074#issuecomment-327484250

That would explain it. So it gives me no choice to have it on the backend side, which is indeed the best solution but I just wanted to do a quick Proof Of Concept with everything on the frontend.

minggangw commented 4 years ago

I see, so I think we could close this issue now. Please feel free to add any comments if you find a workaround.

flynneva commented 4 years ago

@MaximeAubanel I was working on a wrapper of the roslibjs library for react awhile ago. havent made much progress on it since COVID but its still there if you'd like to check it out. react-ros on npm and then the source code should be linked in there as well.

might help you hook react up to ROS.