Skip to content

Commit d6a13a9

Browse files
aduh95MylesBorins
authored andcommitted
doc: document support for package.json fields
Fixes: #33143 Backport-PR-URL: #35757 PR-URL: #34970 Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 7c1700e commit d6a13a9

File tree

4 files changed

+276
-142
lines changed

4 files changed

+276
-142
lines changed

doc/api/errors.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -1357,13 +1357,13 @@ An invalid or unknown file encoding was passed.
13571357
<a id="ERR_INVALID_PACKAGE_CONFIG"></a>
13581358
### `ERR_INVALID_PACKAGE_CONFIG`
13591359

1360-
An invalid `package.json` file was found which failed parsing.
1360+
An invalid [`package.json`][] file was found which failed parsing.
13611361

13621362
<a id="ERR_INVALID_PACKAGE_TARGET"></a>
13631363
### `ERR_INVALID_PACKAGE_TARGET`
13641364

1365-
The `package.json` [exports][] field contains an invalid target mapping value
1366-
for the attempted module resolution.
1365+
The `package.json` [`"exports"`][] field contains an invalid target mapping
1366+
value for the attempted module resolution.
13671367

13681368
<a id="ERR_INVALID_PERFORMANCE_MARK"></a>
13691369
### `ERR_INVALID_PERFORMANCE_MARK`
@@ -1686,13 +1686,13 @@ A given value is out of the accepted range.
16861686
<a id="ERR_PACKAGE_IMPORT_NOT_DEFINED"></a>
16871687
### `ERR_PACKAGE_IMPORT_NOT_DEFINED`
16881688

1689-
The `package.json` ["imports" field][] does not define the given internal
1689+
The `package.json` [`"imports"`][] field does not define the given internal
16901690
package specifier mapping.
16911691

16921692
<a id="ERR_PACKAGE_PATH_NOT_EXPORTED"></a>
16931693
### `ERR_PACKAGE_PATH_NOT_EXPORTED`
16941694

1695-
The `package.json` [exports][] field does not export the requested subpath.
1695+
The `package.json` [`"exports"`][] field does not export the requested subpath.
16961696
Because exports are encapsulated, private internal modules that are not exported
16971697
cannot be imported through the package resolution, unless using an absolute URL.
16981698

@@ -2057,7 +2057,7 @@ signal (such as [`subprocess.kill()`][]).
20572057

20582058
`import` a directory URL is unsupported. Instead,
20592059
[self-reference a package using its name][] and [define a custom subpath][] in
2060-
the `"exports"` field of the `package.json` file.
2060+
the [`"exports"`][] field of the [`package.json`][] file.
20612061

20622062
<!-- eslint-skip -->
20632063
```js
@@ -2529,7 +2529,8 @@ closed.
25292529
[crypto digest algorithm]: crypto.html#crypto_crypto_gethashes
25302530
[domains]: domain.html
25312531
[event emitter-based]: events.html#events_class_eventemitter
2532-
[exports]: packages.html#packages_package_entry_points
2532+
[`package.json`]: packages.html#packages_node_js_package_json_field_definitions
2533+
[`"exports"`]: packages.html#packages_exports
25332534
[file descriptors]: https://en.wikipedia.org/wiki/File_descriptor
25342535
[policy]: policy.html
25352536
[stream-based]: stream.html
@@ -2539,4 +2540,4 @@ closed.
25392540
[vm]: vm.html
25402541
[self-reference a package using its name]: packages.html#packages_self_referencing_a_package_using_its_name
25412542
[define a custom subpath]: packages.html#packages_subpath_exports
2542-
["imports" field]: packages.html#packages_internal_package_imports
2543+
[`"imports"`]: packages.html#packages_imports

doc/api/esm.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ specifier resolution, and default behavior.
5555

5656
Node.js treats JavaScript code as CommonJS modules by default.
5757
Authors can tell Node.js to treat JavaScript code as ECMAScript modules
58-
via the `.mjs` file extension, the `package.json` `"type"` field, or the
58+
via the `.mjs` file extension, the `package.json` [`"type"`][] field, or the
5959
`--input-type` flag. See
6060
[Modules: Packages](packages.html#packages_determining_module_system) for more
6161
details.
@@ -260,9 +260,9 @@ can either be an URL-style relative path like `'./file.mjs'` or a package name
260260
like `'fs'`.
261261
262262
Like in CommonJS, files within packages can be accessed by appending a path to
263-
the package name; unless the package’s `package.json` contains an `"exports"`
264-
field, in which case files within packages need to be accessed via the path
265-
defined in `"exports"`.
263+
the package name; unless the package’s [`package.json`][] contains an
264+
[`"exports"`][] field, in which case files within packages need to be accessed
265+
via the path defined in [`"exports"`][].
266266
267267
```js
268268
import { sin, cos } from 'geometry/trigonometry-functions.mjs';
@@ -1223,3 +1223,6 @@ success!
12231223
[6.1.7 Array Index]: https://tc39.es/ecma262/#integer-index
12241224
[Top-Level Await]: https://github.com/tc39/proposal-top-level-await
12251225
[Core modules]: modules.html#modules_core_modules
1226+
[`package.json`]: packages.html#packages_node_js_package_json_field_definitions
1227+
[`"exports"`]: packages.html#packages_exports
1228+
[`"type"`]: packages.html#packages_type

doc/api/modules.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ directories, and then provide a single entry point to those directories.
391391
There are three ways in which a folder may be passed to `require()` as
392392
an argument.
393393

394-
The first is to create a `package.json` file in the root of the folder,
395-
which specifies a `main` module. An example `package.json` file might
394+
The first is to create a [`package.json`][] file in the root of the folder,
395+
which specifies a `main` module. An example [`package.json`][] file might
396396
look like this:
397397

398398
```json
@@ -406,10 +406,10 @@ If this was in a folder at `./some-library`, then
406406

407407
This is the extent of the awareness of `package.json` files within Node.js.
408408

409-
If there is no `package.json` file present in the directory, or if the
410-
`'main'` entry is missing or cannot be resolved, then Node.js
409+
If there is no [`package.json`][] file present in the directory, or if the
410+
[`"main"`][] entry is missing or cannot be resolved, then Node.js
411411
will attempt to load an `index.js` or `index.node` file out of that
412-
directory. For example, if there was no `package.json` file in the above
412+
directory. For example, if there was no [`package.json`][] file in the previous
413413
example, then `require('./some-library')` would attempt to load:
414414

415415
* `./some-library/index.js`
@@ -1154,3 +1154,5 @@ consists of the following keys:
11541154
[`Error.prepareStackTrace(error, trace)`]: https://v8.dev/docs/stack-trace-api#customizing-stack-traces
11551155
[`SourceMap`]: modules.html#modules_class_module_sourcemap
11561156
[Source map v3 format]: https://sourcemaps.info/spec.html#h.mofvlxcwqzej
1157+
[`package.json`]: packages.html#packages_node_js_package_json_field_definitions
1158+
[`"main"`]: packages.html#packages_main

0 commit comments

Comments
 (0)