Skip to content

Interface broken with custom msg: "Error The message required does not exist: {ros2_package}, msg, {ros2_msg} at /{server_dir}/node_modules/rclnodejs/generated/" #1254

Closed

Description

@VickyXR

Description
I firstly created a ROS2 pkg with custom msg, used colcon build in this pkg and successfully tested.
Then I would like to get msg from topic defined in this pkg.
When starting the server, I got the error:

UNCAUGHT EXCEPTION! System Shutting down...
Error The message required does not exist: {ros2_package}, msg, {ros2_msg} at /{server_dir}/node_modules/rclnodejs/generated/

The error still exist even I have sourced the pkg with:

source install/setup.bash 
source /opt/ros/humble/setup.bash 

My code:

ros2Node.js

const rclnodejs = require("rclnodejs");

exports.initROS2 = async () => {
  await rclnodejs.init();
  const node = new rclnodejs.Node("server_node");

  const cmdPublisher = node.createPublisher(
    "pkg/msg/Cmd",
    "/cmd"
  );
  node.subscription = node.createSubscription(
    "pkg/msg/Status",
    "/status",
    (msg) => {
      console.log(
        `[JS]  ${msg.id} status: pos=${msg.position}, err=${msg.error_code}`
      );
    }
  );

  node.spin(node);
  console.log("[ROS2] Node initialized with publisher and subscriber");
  return node;
};

server.js

const app = require("./app");
const ros2Node = require("./utils/ros2Node");

// start ROS2 node
const node = ros2Node.initROS2();

// start server
const port = 3000;
app.listen(port, () => {
  console.log(`App running on port ${port}...`);
});

I have tried to make my server project as a ros2 pkg,
ros2 pkg create web_interface --build-type ament_nodejs --dependencies rclnodejs
but got error:
ros2 pkg create: error: argument --build-type: invalid choice: 'ament_nodejs' (choose from 'cmake', 'ament_cmake', 'ament_python')

using npx npx generate-ros-messages
got error: sh: 1: generate-ros-messages: Exec format error

using npm npm run generate-messages-idl
got error:

npm error Missing script: "generate-messages-idl"
npm error
npm error To see a list of scripts, run:
npm error   npm run
npm error A complete log of this run can be found in: /home/vicky/.npm/_logs/2025-09-07T06_21_38_347Z-debug-0.log
  • Library Version: 1.5.0
  • ROS Version: humble
  • Platform / OS: Ubuntu 22.04 LTS
  • Node version: 20.19.4

Steps To Reproduce
run node server.js in terminal.

Activity

  1. minggangw commented on Sep 8, 2025

    @minggangw
    Member

    hi @VickyXR thanks for yoru feedback! When you introducing new package of msg/srv/action, you need to run

    Image

    See details, i think we can do some improvement definitely here, like scan if any new package installed, and if yes, we can generate the JavaScript messages in runtime.

  2. VickyXR commented on Sep 8, 2025

    @VickyXR
    Author

    @minggangw Problem solved! The error was caused by the file generate-ros-messages. I have used gedit to check it and found:

    IntxLNK../rclnodejs/scripts/generate_messages.js
    
    

    Maybe it was some unclear error caused during my first installation, just like the error in my last issue > <. Then I removed and installed it again, the content of this file was well fixed!

    Thanks for your attention!

  3. minggangw commented on Sep 10, 2025

    @minggangw
    Member

    After #1257 lands , running npx generate-ros-messages is not needed anymore if new message added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions