"main"


{
  "main": "./main.js"
}
require('./path/to/directory'); // 这解析为 ./path/to/directory/main.js。

当包具有 "exports" 字段时,则在按名称导入包时,这将优先于 "main" 字段。

{
  "main": "./main.js"
}

The "main" field defines the script that is used when the package directory is loaded via require(). Its value is interpreted as a path.

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.