diff options
author | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2021-06-01 16:10:32 +0300 |
---|---|---|
committer | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2021-06-03 17:18:40 +0300 |
commit | 2481facd9ff3af57924c2391c507f13abf73ba3a (patch) | |
tree | fc129276a55a4c56d0e64bdbe927dd70aa868794 /doc/api/packages.md | |
parent | 47548d0c81c63a9b760c3c3e0b4b62e1c1ea06e3 (diff) |
tools,doc: forbid CJS globals in ESM code snippets
PR-URL: https://github.com/nodejs/node/pull/38889
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Danielle Adams <adamzdanielle@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Diffstat (limited to 'doc/api/packages.md')
-rw-r--r-- | doc/api/packages.md | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/doc/api/packages.md b/doc/api/packages.md index 6e87336a009..4e7c8691a98 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -704,7 +704,7 @@ import { another } from 'a-package/m.mjs'; Self-referencing is also available when using `require`, both in an ES module, and in a CommonJS one. For example, this code will also work: -```js +```cjs // ./a-module.js const { something } = require('a-package/foo'); // Loads from ./foo.js. ``` @@ -807,7 +807,7 @@ to be treated as ES modules, just as `"type": "commonjs"` would cause them to be treated as CommonJS. See [Enabling](#esm_enabling). -```js +```cjs // ./node_modules/pkg/index.cjs exports.name = 'value'; ``` @@ -920,7 +920,7 @@ CommonJS and ES module instances of the package: CommonJS and ES module versions of the package. For example, if the CommonJS and ES module entry points are `index.cjs` and `index.mjs`, respectively: - ```js + ```cjs // ./node_modules/pkg/index.cjs const state = require('./state.cjs'); module.exports.state = state; @@ -1034,7 +1034,7 @@ The `"main"` field defines the script that is used when the [package directory is loaded via `require()`](modules.md#modules_folders_as_modules). Its value is a path. -```js +```cjs require('./path/to/directory'); // This resolves to ./path/to/directory/main.js. ``` |