Node.js package.json 字段定义


【Node.js package.json field definitions】

本节描述了 Node.js 运行时使用的字段。其他工具(例如 npm)使用额外的字段,这些字段在 Node.js 中会被忽略,并且在此处未作记录。

【This section describes the fields used by the Node.js runtime. Other tools (such as npm) use additional fields which are ignored by Node.js and not documented here.】

package.json 文件中的以下字段在 Node.js 中使用:

【The following fields in package.json files are used in Node.js:】

  • "name" - 在包中使用具名导入时相关。也被包管理器用作包的名称。
  • "main" - 加载包时的默认模块,如果未指定 exports,并且在 Node.js 引入 exports 之前的版本中。
  • "packageManager" - 在为该软件包贡献时推荐的包管理器。由 Corepack 插件使用。
  • "type" - 包类型决定是否将 .js 文件作为 CommonJS 或 ES 模块加载。
  • "exports" - 包导出和条件导出。当存在时,限制可以从包内部加载的子模块。
  • "imports" - 包导入,供包内模块自身使用。