File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -664,6 +664,32 @@ and in a CommonJS one. For example, this code will also work:
664664const { something } = require (' a-package/foo' ); // Loads from ./foo.js.
665665```
666666
667+ Finally, self-referencing also works with scoped packages. For example, this
668+ code will also work:
669+
670+ ``` json
671+ // package.json
672+ {
673+ "name" : " @my/package" ,
674+ "exports" : " ./index.js"
675+ }
676+ ```
677+
678+ ``` js
679+ // ./index.js
680+ module .exports = 42 ;
681+ ```
682+
683+ ``` js
684+ // ./other.js
685+ console .log (require (' @my/package' ));
686+ ```
687+
688+ ``` console
689+ $ node other.js
690+ 42
691+ ```
692+
667693## Dual CommonJS/ES module packages
668694
669695Prior to the introduction of support for ES modules in Node.js, it was a common
You can’t perform that action at this time.
0 commit comments