Skip to content

Commit 3c24762

Browse files
committed
include explicit example
1 parent a05249d commit 3c24762

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

doc/api/modules.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,9 @@ To create an ESM module that should provide an arbitrary value to CommonJS, the
238238
```mjs
239239
// point.mjs
240240
export default class Point {
241-
constructor(c, x) { this.x = x; this.y = y; }
241+
constructor(x, y) { this.x = x; this.y = y; }
242242
}
243+
export function distance(a, b) { return (b.x - a.x) ** 2 + (b.y - a.y) ** 2; }
243244
export const cjsUnwrapDefault = true;
244245
```
245246

@@ -250,7 +251,9 @@ console.log(point);
250251
```
251252

252253
When using `cjsUnwrapDefault`, no named exports other than the `default` export
253-
will be accessible to CommonJS importers.
254+
will be accessible to CommonJS importers - `distance` is not available for CJS
255+
consumers in the above `require('./point.mjs')`. Instead it should be made a
256+
property of the class (e.g. as a static method).
254257

255258
If the module being `require()`'d contains top-level `await`, or the module
256259
graph it `import`s contains top-level `await`,

0 commit comments

Comments
 (0)