From 7dc3b74c3449a859b4f36400142b3a9e467de9c8 Mon Sep 17 00:00:00 2001 From: Antoine du HAMEL Date: Sat, 22 Aug 2020 11:33:30 +0200 Subject: [PATCH] doc: add ESM examples in `module` API doc page PR-URL: https://github.com/nodejs/node/pull/34875 Reviewed-By: Myles Borins Reviewed-By: Guy Bedford --- doc/api/module.md | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/doc/api/module.md b/doc/api/module.md index 9ce16900fbbdcc..89202038d7c10f 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -7,8 +7,8 @@ * {Object} Provides general utility methods when interacting with instances of -`Module`, the `module` variable often seen in file modules. Accessed -via `require('module')`. +`Module`, the [`module`][] variable often seen in [CommonJS][] modules. Accessed +via `import 'module'` or `require('module')`. ### `module.builtinModules` The `module.syncBuiltinESMExports()` method updates all the live bindings for -builtin ES Modules to match the properties of the CommonJS exports. It does -not add or remove exported names from the ES Modules. +builtin [ES Modules][] to match the properties of the [CommonJS][] exports. It +does not add or remove exported names from the [ES Modules][]. ```js const fs = require('fs'); @@ -116,6 +124,14 @@ To enable source map parsing, Node.js must be run with the flag [`NODE_V8_COVERAGE=dir`][]. ```js +// module.mjs +// In an ECMAScript module +import { findSourceMap, SourceMap } from 'module'; +``` + +```js +// module.cjs +// In a CommonJS module const { findSourceMap, SourceMap } = require('module'); ``` @@ -192,3 +208,6 @@ consists of the following keys: [`Error.prepareStackTrace(error, trace)`]: https://v8.dev/docs/stack-trace-api#customizing-stack-traces [`SourceMap`]: #module_class_module_sourcemap [Source map v3 format]: https://sourcemaps.info/spec.html#h.mofvlxcwqzej +[`module`]: modules.html#modules_the_module_object +[CommonJS]: modules.html +[ES Modules]: esm.html