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 @@ -709,6 +709,32 @@ and in a CommonJS one. For example, this code will also work:
709
709
const { something } = require (' a-package/foo' ); // Loads from ./foo.js.
710
710
```
711
711
712
+ Finally, self-referencing also works with scoped packages. For example, this
713
+ code will also work:
714
+
715
+ ``` json
716
+ // package.json
717
+ {
718
+ "name" : " @my/package" ,
719
+ "exports" : " ./index.js"
720
+ }
721
+ ```
722
+
723
+ ``` js
724
+ // ./index.js
725
+ module .exports = 42 ;
726
+ ```
727
+
728
+ ``` js
729
+ // ./other.js
730
+ console .log (require (' @my/package' ));
731
+ ```
732
+
733
+ ``` console
734
+ $ node other.js
735
+ 42
736
+ ```
737
+
712
738
## Dual CommonJS/ES module packages
713
739
714
740
Prior 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