From 211a3c4c4c1a3cf2481330f8b284471582482337 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 6b38d238dc9949..7a25699c55a1f9 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -1138,17 +1138,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"`