From 86644b95a5de790b0171530d93866dbef10002f0 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sun, 30 Jan 2022 06:26:22 -0800 Subject: [PATCH] doc: clarify that import also uses main PR-URL: https://github.com/nodejs/node/pull/41720 Reviewed-By: Geoffrey Booth Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Antoine du Hamel --- doc/api/packages.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/doc/api/packages.md b/doc/api/packages.md index a24c99f1eeb783..4638c7cc28d9a2 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -1093,17 +1093,19 @@ added: v0.4.0 } ``` -The `"main"` field defines the script that is used when the [package directory -is loaded via `require()`](modules.md#folders-as-modules). Its value -is a path. +The `"main"` field defines the entry point of a package when imported by name +via a `node_modules` lookup. Its value is a path. + +When a package has an [`"exports"`][] field, this will take precedence over the +`"main"` field when importing the package by name. + +It also defines the script that is used when the [package directory is loaded +via `require()`](modules.md#folders-as-modules). ```cjs require('./path/to/directory'); // This resolves to ./path/to/directory/main.js. ``` -When a package has an [`"exports"`][] field, this will take precedence over the -`"main"` field when importing the package by name. - ### `"packageManager"`