@@ -436,8 +436,8 @@ If the given path does not exist, `require()` will throw an [`Error`][] with its
436
436
437
437
<!-- type=misc-->
438
438
439
- It is convenient to organize programs and libraries into self-contained
440
- directories, and then provide a single entry point to those directories.
439
+ > Stability: 3 - Legacy: Use [ subpath exports ] [ ] or [ subpath imports ] [ ] instead.
440
+
441
441
There are three ways in which a folder may be passed to ` require() ` as
442
442
an argument.
443
443
@@ -454,8 +454,6 @@ If this was in a folder at `./some-library`, then
454
454
` require('./some-library') ` would attempt to load
455
455
` ./some-library/lib/some-library.js ` .
456
456
457
- This is the extent of the awareness of ` package.json ` files within Node.js.
458
-
459
457
If there is no [ ` package.json ` ] [ ] file present in the directory, or if the
460
458
[ ` "main" ` ] [ ] entry is missing or cannot be resolved, then Node.js
461
459
will attempt to load an ` index.js ` or ` index.node ` file out of that
@@ -472,6 +470,11 @@ with the default error:
472
470
Error: Cannot find module 'some-library'
473
471
```
474
472
473
+ In all three above cases, an ` import('./some-library') ` call would result in a
474
+ [ ` ERR_UNSUPPORTED_DIR_IMPORT ` ] [ ] error. Using package [ subpath exports] [ ] or
475
+ [ subpath imports] [ ] can provide the same containment organization benefits as
476
+ folders as modules, and work for both ` require ` and ` import ` .
477
+
475
478
## Loading from ` node_modules ` folders
476
479
477
480
<!-- type=misc-->
@@ -1080,6 +1083,7 @@ This section was moved to
1080
1083
[ `"main"` ] : packages.md#main
1081
1084
[ `"type"` ] : packages.md#type
1082
1085
[ `ERR_REQUIRE_ESM` ] : errors.md#err_require_esm
1086
+ [ `ERR_UNSUPPORTED_DIR_IMPORT` ] : errors.md#err_unsupported_dir_import
1083
1087
[ `Error` ] : errors.md#class-error
1084
1088
[ `__dirname` ] : #__dirname
1085
1089
[ `__filename` ] : #__filename
@@ -1094,3 +1098,5 @@ This section was moved to
1094
1098
[ exports shortcut ] : #exports-shortcut
1095
1099
[ module resolution ] : #all-together
1096
1100
[ native addons ] : addons.md
1101
+ [ subpath exports ] : packages.md#subpath-exports
1102
+ [ subpath imports ] : packages.md#subpath-imports
0 commit comments