Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorJesús Leganés-Combarro 'piranna <piranna@gmail.com>2021-03-06 15:53:50 +0300
committerMichaël Zasso <targos@protonmail.com>2021-09-04 16:14:53 +0300
commit2624c982078e60a2b1e103e879da07d83f119031 (patch)
tree9ef62e996c3b24b7d82efaea6136c80a8fa92ed8 /doc
parent00f2cee26c47f7ee9b855bc350d50237a84abf4d (diff)
doc: add example of self-reference in scoped packages
PR-URL: https://github.com/nodejs/node/pull/37630 Fixes: https://github.com/nodejs/node/issues/37618 Refs: https://github.com/nodejs/node/issues/37618#issuecomment-791888177 Co-authored-by: Michaël Zasso <targos@protonmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/packages.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/doc/api/packages.md b/doc/api/packages.md
index ff17c9890bf..473cdba4389 100644
--- a/doc/api/packages.md
+++ b/doc/api/packages.md
@@ -664,6 +664,32 @@ and in a CommonJS one. For example, this code will also work:
const { something } = require('a-package/foo'); // Loads from ./foo.js.
```
+Finally, self-referencing also works with scoped packages. For example, this
+code will also work:
+
+```json
+// package.json
+{
+ "name": "@my/package",
+ "exports": "./index.js"
+}
+```
+
+```js
+// ./index.js
+module.exports = 42;
+```
+
+```js
+// ./other.js
+console.log(require('@my/package'));
+```
+
+```console
+$ node other.js
+42
+```
+
## Dual CommonJS/ES module packages
Prior to the introduction of support for ES modules in Node.js, it was a common