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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions