Skip to content

Commit 610dada

Browse files
authored
[Doc] Switch npmjs README examples to ESM (#1542)
Align the npm-published README (scripts/npmjs-readme.md) with the package's ESM-first API. - Quick-start snippet: replace the CommonJS `require()` + `init().then()` form with native ESM `import rclnodejs from 'rclnodejs'` and top-level `await rclnodejs.init()`. - TypeScript guidance: update the sample tsconfig from `commonjs` / `node` / `es2020` to `NodeNext` / `NodeNext` / `es2022` to match ESM module resolution. Fix: #1541
1 parent 3c5df58 commit 610dada

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

scripts/npmjs-readme.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
Supported ROS 2 distributions include Humble, Jazzy, Kilted, Lyrical, and Rolling.
66

77
```javascript
8-
const rclnodejs = require('rclnodejs');
9-
rclnodejs.init().then(() => {
10-
const node = new rclnodejs.Node('publisher_example_node');
11-
const publisher = node.createPublisher('std_msgs/msg/String', 'topic');
12-
publisher.publish(`Hello ROS 2 from rclnodejs`);
13-
node.spin();
14-
});
8+
import rclnodejs from 'rclnodejs';
9+
10+
await rclnodejs.init();
11+
const node = new rclnodejs.Node('publisher_example_node');
12+
const publisher = node.createPublisher('std_msgs/msg/String', 'topic');
13+
publisher.publish(`Hello ROS 2 from rclnodejs`);
14+
node.spin();
1515
```
1616

1717
This example assumes your ROS 2 environment is already sourced.
@@ -87,9 +87,9 @@ TypeScript declaration files are included in the package. In most projects, conf
8787
```jsonc
8888
{
8989
"compilerOptions": {
90-
"module": "commonjs",
91-
"moduleResolution": "node",
92-
"target": "es2020",
90+
"module": "NodeNext",
91+
"moduleResolution": "NodeNext",
92+
"target": "es2022",
9393
},
9494
}
9595
```

0 commit comments

Comments
 (0)