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
316 stars 70 forks source link

Nav2_msg require error #729

Closed adamkrawczyk closed 3 years ago

adamkrawczyk commented 3 years ago

version: rclnodejs@0.16.0 ros: ros2 foxy

when:

const nav2_msgs = rclnodejs.require('nav2_msgs').msg;

what:

/path/nodejs/node_modules/rclnodejs/lib/interface_loader.js:86
Object.defineProperty(pkg[info.type], info.name, {
              ^

TypeError: Object.defineProperty called on non-object
at Function.defineProperty (<anonymous>)
at /path/nodejs/node_modules/rclnodejs/lib/interface_loader.js:86:14
at Array.forEach (<anonymous>)
at Object.loadInterfaceByPath (/parth/nodejs/node_modules/rclnodejs/lib/interface_loader.js:85:20)
at Object.loadInterfaceByString (/path/nodejs/node_modules/rclnodejs/lib/interface_loader.js:65:19)
at Object.loadInterface (/path/nodejs/node_modules/rclnodejs/lib/interface_loader.js:100:21)
at Object.require (path/nodejs/node_modules/rclnodejs/index.js:334:19)
at Object.<anonymous> (/path/nodejs/main.js:20:29)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)

Why:

I have no idea why this occurs. Other messages are imported properly. Nav2_msgs are generated.

minggangw commented 3 years ago

If nav2_msgs is not a ROS2 build-in package (released with ROS2 package), I think you have to source its local_setup.bash so the message generator could find this package and create the JS file for it.

wayneparrott commented 3 years ago

@adamkrawczyk thx for sharing this issue. nav2_msgs includes a number of actions. When support for actions was added earlier this year we missed updating interface_loader.loadInterfaceByPath() to recognize actions.

The fix is to change line 84 from:

    let pkg = { srv: {}, msg: {} };

to

    let pkg = { srv: {}, msg: {}, action: {} };
minggangw commented 3 years ago

Oh, I missed @adamkrawczyk has mentioned that

Nav2_msgs are generated.

So I think the .bash has been sourced. Thanks for @wayneparrott's findings.

adamkrawczyk commented 3 years ago

Yeah!

This is solving the issue. (rclnodejs/lib/interface_loader.js 84: let pkg = { srv: {}, msg: {}, action: {} };)

When the npm version will be patched?

Thank you ;)

wayneparrott commented 3 years ago

@minggangw I can submit a PR with fix and test case if no one else is planning to work this issue. Thoughts?

minggangw commented 3 years ago

@wayneparrott Please submit a PR to fix this issue, thanks!

When the npm version will be patched?

Hopefully, the next release v0.17.0 can land the patch and we will publish it once the current issues get addressed.