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