{
  "type": "module",
  "source": "doc/api/packages.md",
  "introduced_in": "v12.20.0",
  "meta": {
    "changes": [
      {
        "version": [
          "v14.13.0",
          "v12.20.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/34718",
        "description": "Add support for `\"exports\"` patterns."
      },
      {
        "version": [
          "v14.6.0",
          "v12.19.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/34117",
        "description": "Add package `\"imports\"` field."
      },
      {
        "version": [
          "v13.7.0",
          "v12.17.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/29866",
        "description": "Unflag conditional exports."
      },
      {
        "version": [
          "v13.7.0",
          "v12.16.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/31001",
        "description": "Remove the `--experimental-conditional-exports` option. In 12.16.0, conditional exports are still behind `--experimental-modules`."
      },
      {
        "version": [
          "v13.6.0",
          "v12.16.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/31002",
        "description": "Unflag self-referencing a package using its name."
      },
      {
        "version": "v12.7.0",
        "pr-url": "https://github.com/nodejs/node/pull/28568",
        "description": "Introduce `\"exports\"` `package.json` field as a more powerful alternative to the classic `\"main\"` field."
      },
      {
        "version": "v12.0.0",
        "pr-url": "https://github.com/nodejs/node/pull/26745",
        "description": "Add support for ES modules using `.js` file extension via `package.json` `\"type\"` field."
      }
    ]
  },
  "miscs": [
    {
      "textRaw": "Modules: Packages",
      "name": "Modules: Packages",
      "introduced_in": "v12.20.0",
      "type": "misc",
      "meta": {
        "changes": [
          {
            "version": [
              "v14.13.0",
              "v12.20.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/34718",
            "description": "Add support for `\"exports\"` patterns."
          },
          {
            "version": [
              "v14.6.0",
              "v12.19.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/34117",
            "description": "Add package `\"imports\"` field."
          },
          {
            "version": [
              "v13.7.0",
              "v12.17.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/29866",
            "description": "Unflag conditional exports."
          },
          {
            "version": [
              "v13.7.0",
              "v12.16.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/31001",
            "description": "Remove the `--experimental-conditional-exports` option. In 12.16.0, conditional exports are still behind `--experimental-modules`."
          },
          {
            "version": [
              "v13.6.0",
              "v12.16.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/31002",
            "description": "Unflag self-referencing a package using its name."
          },
          {
            "version": "v12.7.0",
            "pr-url": "https://github.com/nodejs/node/pull/28568",
            "description": "Introduce `\"exports\"` `package.json` field as a more powerful alternative to the classic `\"main\"` field."
          },
          {
            "version": "v12.0.0",
            "pr-url": "https://github.com/nodejs/node/pull/26745",
            "description": "Add support for ES modules using `.js` file extension via `package.json` `\"type\"` field."
          }
        ]
      },
      "miscs": [
        {
          "textRaw": "Introduction",
          "name": "introduction",
          "type": "misc",
          "desc": "<p>A package is a folder tree described by a <code>package.json</code> file. The package\nconsists of the folder containing the <code>package.json</code> file and all subfolders\nuntil the next folder containing another <code>package.json</code> file, or a folder\nnamed <code>node_modules</code>.</p>\n<p>This page provides guidance for package authors writing <code>package.json</code> files\nalong with a reference for the <a href=\"#nodejs-packagejson-field-definitions\"><code>package.json</code></a> fields defined by Node.js.</p>",
          "displayName": "Introduction"
        },
        {
          "textRaw": "Determining module system",
          "name": "determining_module_system",
          "type": "misc",
          "modules": [
            {
              "textRaw": "Introduction",
              "name": "introduction",
              "type": "module",
              "desc": "<p>Node.js will treat the following as <a href=\"esm.html\">ES modules</a> when passed to <code>node</code> as the\ninitial input, or when referenced by <code>import</code> statements or <code>import()</code>\nexpressions:</p>\n<ul>\n<li>\n<p>Files with an <code>.mjs</code> extension.</p>\n</li>\n<li>\n<p>Files with a <code>.js</code> extension when the nearest parent <code>package.json</code> file\ncontains a top-level <a href=\"#type\"><code>\"type\"</code></a> field with a value of <code>\"module\"</code>.</p>\n</li>\n<li>\n<p>Strings passed in as an argument to <code>--eval</code>, or piped to <code>node</code> via <code>STDIN</code>,\nwith the flag <code>--input-type=module</code>.</p>\n</li>\n<li>\n<p>Code containing syntax only successfully parsed as <a href=\"esm.html\">ES modules</a>, such as\n<code>import</code> or <code>export</code> statements or <code>import.meta</code>, with no explicit marker of\nhow it should be interpreted. Explicit markers are <code>.mjs</code> or <code>.cjs</code>\nextensions, <code>package.json</code> <code>\"type\"</code> fields with either <code>\"module\"</code> or\n<code>\"commonjs\"</code> values, or the <code>--input-type</code> flag. Dynamic <code>import()</code>\nexpressions are supported in either CommonJS or ES modules and would not force\na file to be treated as an ES module. See <a href=\"#syntax-detection\">Syntax detection</a>.</p>\n</li>\n</ul>\n<p>Node.js will treat the following as <a href=\"modules.html\">CommonJS</a> when passed to <code>node</code> as the\ninitial input, or when referenced by <code>import</code> statements or <code>import()</code>\nexpressions:</p>\n<ul>\n<li>\n<p>Files with a <code>.cjs</code> extension.</p>\n</li>\n<li>\n<p>Files with a <code>.js</code> extension when the nearest parent <code>package.json</code> file\ncontains a top-level field <a href=\"#type\"><code>\"type\"</code></a> with a value of <code>\"commonjs\"</code>.</p>\n</li>\n<li>\n<p>Strings passed in as an argument to <code>--eval</code> or <code>--print</code>, or piped to <code>node</code>\nvia <code>STDIN</code>, with the flag <code>--input-type=commonjs</code>.</p>\n</li>\n<li>\n<p>Files with a <code>.js</code> extension with no parent <code>package.json</code> file or where the\nnearest parent <code>package.json</code> file lacks a <code>type</code> field, and where the code\ncan evaluate successfully as CommonJS. In other words, Node.js tries to run\nsuch \"ambiguous\" files as CommonJS first, and will retry evaluating them as ES\nmodules if the evaluation as CommonJS fails because the parser found ES module\nsyntax.</p>\n</li>\n</ul>\n<p>Writing ES module syntax in \"ambiguous\" files incurs a performance cost, and\ntherefore it is encouraged that authors be explicit wherever possible. In\nparticular, package authors should always include the <a href=\"#type\"><code>\"type\"</code></a> field in\ntheir <code>package.json</code> files, even in packages where all sources are CommonJS.\nBeing explicit about the <code>type</code> of the package will future-proof the package in\ncase the default type of Node.js ever changes, and it will also make things\neasier for build tools and loaders to determine how the files in the package\nshould be interpreted.</p>",
              "displayName": "Introduction"
            },
            {
              "textRaw": "Syntax detection",
              "name": "syntax_detection",
              "type": "module",
              "meta": {
                "added": [
                  "v21.1.0",
                  "v20.10.0"
                ],
                "changes": [
                  {
                    "version": [
                      "v22.7.0",
                      "v20.19.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/53619",
                    "description": "Syntax detection is enabled by default."
                  }
                ]
              },
              "stability": 1.2,
              "stabilityText": "Release candidate",
              "desc": "<p>Node.js will inspect the source code of ambiguous input to determine whether it\ncontains ES module syntax; if such syntax is detected, the input will be treated\nas an ES module.</p>\n<p>Ambiguous input is defined as:</p>\n<ul>\n<li>Files with a <code>.js</code> extension or no extension; and either no controlling\n<code>package.json</code> file or one that lacks a <code>type</code> field.</li>\n<li>String input (<code>--eval</code> or <code>STDIN</code>) when <code>--input-type</code>is not specified.</li>\n</ul>\n<p>ES module syntax is defined as syntax that would throw when evaluated as\nCommonJS. This includes the following:</p>\n<ul>\n<li><code>import</code> statements (but <em>not</em> <code>import()</code> expressions, which are valid in\nCommonJS).</li>\n<li><code>export</code> statements.</li>\n<li><code>import.meta</code> references.</li>\n<li><code>await</code> at the top level of a module.</li>\n<li>Lexical redeclarations of the CommonJS wrapper variables (<code>require</code>, <code>module</code>,\n<code>exports</code>, <code>__dirname</code>, <code>__filename</code>).</li>\n</ul>",
              "displayName": "Syntax detection"
            },
            {
              "textRaw": "Module resolution and loading",
              "name": "module_resolution_and_loading",
              "type": "module",
              "desc": "<p>Node.js has two types of module resolution and loading, chosen based on how the module is requested.</p>\n<p>When a module is requested via <code>require()</code> (available by default in CommonJS modules,\nand can be dynamically generated using <code>createRequire()</code> in both CommonJS and ES Modules):</p>\n<ul>\n<li>Resolution:\n<ul>\n<li>The resolution initiated by <code>require()</code> supports <a href=\"modules.html#folders-as-modules\">folders as modules</a>.</li>\n<li>When resolving a specifier, if no exact match is found, <code>require()</code> will try to add\nextensions (<code>.js</code>, <code>.json</code>, and finally <code>.node</code>) and then attempt to resolve\n<a href=\"modules.html#folders-as-modules\">folders as modules</a>.</li>\n<li>It does not support URLs as specifiers by default.</li>\n</ul>\n</li>\n<li>Loading:\n<ul>\n<li><code>.json</code> files are treated as JSON text files.</li>\n<li><code>.node</code> files are interpreted as compiled addon modules loaded with <code>process.dlopen()</code>.</li>\n<li><code>.ts</code>, <code>.mts</code> and <code>.cts</code> files are treated as <a href=\"typescript.html\">TypeScript</a> text files.</li>\n<li>Files with any other extension, or without extensions, are treated as JavaScript\ntext files.</li>\n<li><code>require()</code> can only be used to <a href=\"modules.html#loading-ecmascript-modules-using-require\">load ECMAScript modules from CommonJS modules</a> if\nthe <a href=\"esm.html\">ECMAScript module</a> <em>and its dependencies</em> are synchronous\n(i.e. they do not contain top-level <code>await</code>).</li>\n</ul>\n</li>\n</ul>\n<p>When a module is requested via static <code>import</code> statements (only available in ES Modules)\nor <code>import()</code> expressions (available in both CommonJS and ES Modules):</p>\n<ul>\n<li>Resolution:\n<ul>\n<li>The resolution of <code>import</code>/<code>import()</code> does not support folders as modules,\ndirectory indexes (e.g. <code>'./startup/index.js'</code>) must be fully specified.</li>\n<li>It does not perform extension searching. A file extension must be provided\nwhen the specifier is a relative or absolute file URL.</li>\n<li>It supports <code>file://</code> and <code>data:</code> URLs as specifiers by default.</li>\n</ul>\n</li>\n<li>Loading:\n<ul>\n<li><code>.json</code> files are treated as JSON text files. When importing JSON modules,\nan import type attribute is required (e.g.\n<code>import json from './data.json' with { type: 'json' }</code>).</li>\n<li><code>.node</code> files are interpreted as compiled addon modules loaded with\n<code>process.dlopen()</code>, if <a href=\"cli.html#--experimental-addon-modules\"><code>--experimental-addon-modules</code></a> is enabled.</li>\n<li><code>.ts</code>, <code>.mts</code> and <code>.cts</code> files are treated as <a href=\"typescript.html\">TypeScript</a> text files.</li>\n<li>It accepts only <code>.js</code>, <code>.mjs</code>, and <code>.cjs</code> extensions for JavaScript text\nfiles.</li>\n<li><code>.wasm</code> files are treated as <a href=\"esm.html#wasm-modules\">WebAssembly modules</a>.</li>\n<li>Any other file extensions will result in a  <a href=\"errors.html#err_unknown_file_extension\"><code>ERR_UNKNOWN_FILE_EXTENSION</code></a> error.\nAdditional file extensions can be facilitated via <a href=\"module.html#customization-hooks\">customization hooks</a>.</li>\n<li><code>import</code>/<code>import()</code> can be used to load JavaScript <a href=\"modules.html\">CommonJS modules</a>.\nSuch modules are passed through <a href=\"https://github.com/anonrig/merve\">merve</a> to try to identify named\nexports, which are available if they can be determined through static analysis.</li>\n</ul>\n</li>\n</ul>\n<p>Regardless of how a module is requested, the resolution and loading process can be customized\nusing <a href=\"module.html#customization-hooks\">customization hooks</a>.</p>",
              "displayName": "Module resolution and loading"
            },
            {
              "textRaw": "`package.json` and file extensions",
              "name": "`package.json`_and_file_extensions",
              "type": "module",
              "desc": "<p>Within a package, the <a href=\"#nodejs-packagejson-field-definitions\"><code>package.json</code></a> <a href=\"#type\"><code>\"type\"</code></a> field defines how\nNode.js should interpret <code>.js</code> files. If a <code>package.json</code> file does not have a\n<code>\"type\"</code> field, <code>.js</code> files are treated as <a href=\"modules.html\">CommonJS</a>.</p>\n<p>A <code>package.json</code> <code>\"type\"</code> value of <code>\"module\"</code> tells Node.js to interpret <code>.js</code>\nfiles within that package as using <a href=\"esm.html\">ES module</a> syntax.</p>\n<p>The <code>\"type\"</code> field applies not only to initial entry points (<code>node my-app.js</code>)\nbut also to files referenced by <code>import</code> statements and <code>import()</code> expressions.</p>\n<pre><code class=\"language-js\">// my-app.js, treated as an ES module because there is a package.json\n// file in the same folder with \"type\": \"module\".\n\nimport './startup/init.js';\n// Loaded as ES module since ./startup contains no package.json file,\n// and therefore inherits the \"type\" value from one level up.\n\nimport 'commonjs-package';\n// Loaded as CommonJS since ./node_modules/commonjs-package/package.json\n// lacks a \"type\" field or contains \"type\": \"commonjs\".\n\nimport './node_modules/commonjs-package/index.js';\n// Loaded as CommonJS since ./node_modules/commonjs-package/package.json\n// lacks a \"type\" field or contains \"type\": \"commonjs\".\n</code></pre>\n<p>Files ending with <code>.mjs</code> are always loaded as <a href=\"esm.html\">ES modules</a> regardless of\nthe nearest parent <code>package.json</code>.</p>\n<p>Files ending with <code>.cjs</code> are always loaded as <a href=\"modules.html\">CommonJS</a> regardless of the\nnearest parent <code>package.json</code>.</p>\n<pre><code class=\"language-js\">import './legacy-file.cjs';\n// Loaded as CommonJS since .cjs is always loaded as CommonJS.\n\nimport 'commonjs-package/src/index.mjs';\n// Loaded as ES module since .mjs is always loaded as ES module.\n</code></pre>\n<p>The <code>.mjs</code> and <code>.cjs</code> extensions can be used to mix types within the same\npackage:</p>\n<ul>\n<li>\n<p>Within a <code>\"type\": \"module\"</code> package, Node.js can be instructed to\ninterpret a particular file as <a href=\"modules.html\">CommonJS</a> by naming it with a <code>.cjs</code>\nextension (since both <code>.js</code> and <code>.mjs</code> files are treated as ES modules within\na <code>\"module\"</code> package).</p>\n</li>\n<li>\n<p>Within a <code>\"type\": \"commonjs\"</code> package, Node.js can be instructed to\ninterpret a particular file as an <a href=\"esm.html\">ES module</a> by naming it with an <code>.mjs</code>\nextension (since both <code>.js</code> and <code>.cjs</code> files are treated as CommonJS within a\n<code>\"commonjs\"</code> package).</p>\n</li>\n</ul>",
              "displayName": "`package.json` and file extensions"
            },
            {
              "textRaw": "`--input-type` flag",
              "name": "`--input-type`_flag",
              "type": "module",
              "meta": {
                "added": [
                  "v12.0.0"
                ],
                "changes": []
              },
              "desc": "<p>Strings passed in as an argument to <code>--eval</code> (or <code>-e</code>), or piped to <code>node</code> via\n<code>STDIN</code>, are treated as <a href=\"esm.html\">ES modules</a> when the <code>--input-type=module</code> flag\nis set.</p>\n<pre><code class=\"language-bash\">node --input-type=module --eval \"import { sep } from 'node:path'; console.log(sep);\"\n\necho \"import { sep } from 'node:path'; console.log(sep);\" | node --input-type=module\n</code></pre>\n<p>For completeness there is also <code>--input-type=commonjs</code>, for explicitly running\nstring input as CommonJS. This is the default behavior if <code>--input-type</code> is\nunspecified.</p>",
              "displayName": "`--input-type` flag"
            }
          ],
          "displayName": "Determining module system"
        },
        {
          "textRaw": "Package entry points",
          "name": "package_entry_points",
          "type": "misc",
          "desc": "<p>In a package's <code>package.json</code> file, two fields can define entry points for a\npackage: <a href=\"#main\"><code>\"main\"</code></a> and <a href=\"#exports\"><code>\"exports\"</code></a>. Both fields apply to both ES module\nand CommonJS module entry points.</p>\n<p>The <a href=\"#main\"><code>\"main\"</code></a> field is supported in all versions of Node.js, but its\ncapabilities are limited: it only defines the main entry point of the package.</p>\n<p>The <a href=\"#exports\"><code>\"exports\"</code></a> provides a modern alternative to <a href=\"#main\"><code>\"main\"</code></a> allowing\nmultiple entry points to be defined, conditional entry resolution support\nbetween environments, and <strong>preventing any other entry points besides those\ndefined in <a href=\"#exports\"><code>\"exports\"</code></a></strong>. This encapsulation allows module authors to\nclearly define the public interface for their package.</p>\n<p>For new packages targeting the currently supported versions of Node.js, the\n<a href=\"#exports\"><code>\"exports\"</code></a> field is recommended. For packages supporting Node.js 10 and\nbelow, the <a href=\"#main\"><code>\"main\"</code></a> field is required. If both <a href=\"#exports\"><code>\"exports\"</code></a> and\n<a href=\"#main\"><code>\"main\"</code></a> are defined, the <a href=\"#exports\"><code>\"exports\"</code></a> field takes precedence over\n<a href=\"#main\"><code>\"main\"</code></a> in supported versions of Node.js.</p>\n<p><a href=\"#conditional-exports\">Conditional exports</a> can be used within <a href=\"#exports\"><code>\"exports\"</code></a> to define different\npackage entry points per environment, including whether the package is\nreferenced via <code>require</code> or via <code>import</code>. For more information about supporting\nboth CommonJS and ES modules in a single package please consult\n<a href=\"#dual-commonjses-module-packages\">the dual CommonJS/ES module packages section</a>.</p>\n<p>Existing packages introducing the <a href=\"#exports\"><code>\"exports\"</code></a> field will prevent consumers\nof the package from using any entry points that are not defined, including the\n<a href=\"#nodejs-packagejson-field-definitions\"><code>package.json</code></a> (e.g. <code>require('your-package/package.json')</code>). <strong>This will\nlikely be a breaking change.</strong></p>\n<p>To make the introduction of <a href=\"#exports\"><code>\"exports\"</code></a> non-breaking, ensure that every\npreviously supported entry point is exported. It is best to explicitly specify\nentry points so that the package's public API is well-defined. For example,\na project that previously exported <code>main</code>, <code>lib</code>,\n<code>feature</code>, and the <code>package.json</code> could use the following <code>package.exports</code>:</p>\n<pre><code class=\"language-json\">{\n  \"name\": \"my-package\",\n  \"exports\": {\n    \".\": \"./lib/index.js\",\n    \"./lib\": \"./lib/index.js\",\n    \"./lib/index\": \"./lib/index.js\",\n    \"./lib/index.js\": \"./lib/index.js\",\n    \"./feature\": \"./feature/index.js\",\n    \"./feature/index\": \"./feature/index.js\",\n    \"./feature/index.js\": \"./feature/index.js\",\n    \"./package.json\": \"./package.json\"\n  }\n}\n</code></pre>\n<p>Alternatively a project could choose to export entire folders both with and\nwithout extensioned subpaths using export patterns:</p>\n<pre><code class=\"language-json\">{\n  \"name\": \"my-package\",\n  \"exports\": {\n    \".\": \"./lib/index.js\",\n    \"./lib\": \"./lib/index.js\",\n    \"./lib/*\": \"./lib/*.js\",\n    \"./lib/*.js\": \"./lib/*.js\",\n    \"./feature\": \"./feature/index.js\",\n    \"./feature/*\": \"./feature/*.js\",\n    \"./feature/*.js\": \"./feature/*.js\",\n    \"./package.json\": \"./package.json\"\n  }\n}\n</code></pre>\n<p>With the above providing backwards-compatibility for any minor package versions,\na future major change for the package can then properly restrict the exports\nto only the specific feature exports exposed:</p>\n<pre><code class=\"language-json\">{\n  \"name\": \"my-package\",\n  \"exports\": {\n    \".\": \"./lib/index.js\",\n    \"./feature/*.js\": \"./feature/*.js\",\n    \"./feature/internal/*\": null\n  }\n}\n</code></pre>",
          "modules": [
            {
              "textRaw": "Main entry point export",
              "name": "main_entry_point_export",
              "type": "module",
              "desc": "<p>When writing a new package, it is recommended to use the <a href=\"#exports\"><code>\"exports\"</code></a> field:</p>\n<pre><code class=\"language-json\">{\n  \"exports\": \"./index.js\"\n}\n</code></pre>\n<p>When the <a href=\"#exports\"><code>\"exports\"</code></a> field is defined, all subpaths of the package are\nencapsulated and no longer available to importers. For example,\n<code>require('pkg/subpath.js')</code> throws an <a href=\"errors.html#err_package_path_not_exported\"><code>ERR_PACKAGE_PATH_NOT_EXPORTED</code></a>\nerror.</p>\n<p>This encapsulation of exports provides more reliable guarantees\nabout package interfaces for tools and when handling semver upgrades for a\npackage. It is not a strong encapsulation since a direct require of any\nabsolute subpath of the package such as\n<code>require('/path/to/node_modules/pkg/subpath.js')</code> will still load <code>subpath.js</code>.</p>\n<p>All currently supported versions of Node.js and modern build tools support the\n<code>\"exports\"</code> field. For projects using an older version of Node.js or a related\nbuild tool, compatibility can be achieved by including the <code>\"main\"</code> field\nalongside <code>\"exports\"</code> pointing to the same module:</p>\n<pre><code class=\"language-json\">{\n  \"main\": \"./index.js\",\n  \"exports\": \"./index.js\"\n}\n</code></pre>",
              "displayName": "Main entry point export"
            },
            {
              "textRaw": "Subpath exports",
              "name": "subpath_exports",
              "type": "module",
              "meta": {
                "added": [
                  "v12.7.0"
                ],
                "changes": []
              },
              "desc": "<p>When using the <a href=\"#exports\"><code>\"exports\"</code></a> field, custom subpaths can be defined along\nwith the main entry point by treating the main entry point as the\n<code>\".\"</code> subpath:</p>\n<pre><code class=\"language-json\">{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./submodule.js\": \"./src/submodule.js\"\n  }\n}\n</code></pre>\n<p>Now only the defined subpath in <a href=\"#exports\"><code>\"exports\"</code></a> can be imported by a consumer:</p>\n<pre><code class=\"language-js\">import submodule from 'es-module-package/submodule.js';\n// Loads ./node_modules/es-module-package/src/submodule.js\n</code></pre>\n<p>While other subpaths will error:</p>\n<pre><code class=\"language-js\">import submodule from 'es-module-package/private-module.js';\n// Throws ERR_PACKAGE_PATH_NOT_EXPORTED\n</code></pre>",
              "modules": [
                {
                  "textRaw": "Extensions in subpaths",
                  "name": "extensions_in_subpaths",
                  "type": "module",
                  "desc": "<p>Package authors should provide either extensioned (<code>import 'pkg/subpath.js'</code>) or\nextensionless (<code>import 'pkg/subpath'</code>) subpaths in their exports. This ensures\nthat there is only one subpath for each exported module so that all dependents\nimport the same consistent specifier, keeping the package contract clear for\nconsumers and simplifying package subpath completions.</p>\n<p>Traditionally, packages tended to use the extensionless style, which has the\nbenefits of readability and of masking the true path of the file within the\npackage.</p>\n<p>With <a href=\"https://github.com/WICG/import-maps\">import maps</a> now providing a standard for package resolution in browsers\nand other JavaScript runtimes, using the extensionless style can result in\nbloated import map definitions. Explicit file extensions can avoid this issue by\nenabling the import map to utilize a <a href=\"https://github.com/WICG/import-maps#packages-via-trailing-slashes\">packages folder mapping</a> to map multiple\nsubpaths where possible instead of a separate map entry per package subpath\nexport. This also mirrors the requirement of using <a href=\"esm.html#mandatory-file-extensions\">the full specifier path</a>\nin relative and absolute import specifiers.</p>",
                  "displayName": "Extensions in subpaths"
                },
                {
                  "textRaw": "Path Rules and Validation for Export Targets",
                  "name": "path_rules_and_validation_for_export_targets",
                  "type": "module",
                  "desc": "<p>When defining paths as targets in the <a href=\"#exports\"><code>\"exports\"</code></a> field, Node.js enforces\nseveral rules to ensure security, predictability, and proper encapsulation.\nUnderstanding these rules is crucial for authors publishing packages.</p>",
                  "modules": [
                    {
                      "textRaw": "Targets must be relative URLs",
                      "name": "targets_must_be_relative_urls",
                      "type": "module",
                      "desc": "<p>All target paths in the <a href=\"#exports\"><code>\"exports\"</code></a> map (the values associated with export\nkeys) must be relative URL strings starting with <code>./</code>.</p>\n<pre><code class=\"language-json\">// package.json\n{\n  \"name\": \"my-package\",\n  \"exports\": {\n    \".\": \"./dist/main.js\",          // Correct\n    \"./feature\": \"./lib/feature.js\", // Correct\n    // \"./origin-relative\": \"/dist/main.js\", // Incorrect: Must start with ./\n    // \"./absolute\": \"file:///dev/null\", // Incorrect: Must start with ./\n    // \"./outside\": \"../common/util.js\" // Incorrect: Must start with ./\n  }\n}\n</code></pre>\n<p>Reasons for this behavior include:</p>\n<ul>\n<li><strong>Security:</strong> Prevents exporting arbitrary files from outside the\npackage's own directory.</li>\n<li><strong>Encapsulation:</strong> Ensures all exported paths are resolved relative to\nthe package root, making the package self-contained.</li>\n</ul>",
                      "displayName": "Targets must be relative URLs"
                    },
                    {
                      "textRaw": "No path traversal or invalid segments",
                      "name": "no_path_traversal_or_invalid_segments",
                      "type": "module",
                      "desc": "<p>Export targets must not resolve to a location outside the package's root\ndirectory. Additionally, path segments like <code>.</code> (single dot), <code>..</code> (double dot),\nor <code>node_modules</code> (and their URL-encoded equivalents) are generally disallowed\nwithin the <code>target</code> string after the initial <code>./</code> and in any <code>subpath</code> part\nsubstituted into a target pattern.</p>\n<pre><code class=\"language-json\">// package.json\n{\n  \"name\": \"my-package\",\n  \"exports\": {\n    // \".\": \"./dist/../../elsewhere/file.js\", // Invalid: path traversal\n    // \".\": \"././dist/main.js\",             // Invalid: contains \".\" segment\n    // \".\": \"./dist/../dist/main.js\",       // Invalid: contains \"..\" segment\n    // \"./utils/./helper.js\": \"./utils/helper.js\" // Key has invalid segment\n  }\n}\n</code></pre>",
                      "displayName": "No path traversal or invalid segments"
                    }
                  ],
                  "displayName": "Path Rules and Validation for Export Targets"
                }
              ],
              "displayName": "Subpath exports"
            },
            {
              "textRaw": "Exports sugar",
              "name": "exports_sugar",
              "type": "module",
              "meta": {
                "added": [
                  "v12.11.0"
                ],
                "changes": []
              },
              "desc": "<p>If the <code>\".\"</code> export is the only export, the <a href=\"#exports\"><code>\"exports\"</code></a> field provides sugar\nfor this case being the direct <a href=\"#exports\"><code>\"exports\"</code></a> field value.</p>\n<pre><code class=\"language-json\">{\n  \"exports\": {\n    \".\": \"./index.js\"\n  }\n}\n</code></pre>\n<p>can be written:</p>\n<pre><code class=\"language-json\">{\n  \"exports\": \"./index.js\"\n}\n</code></pre>",
              "displayName": "Exports sugar"
            },
            {
              "textRaw": "Subpath imports",
              "name": "subpath_imports",
              "type": "module",
              "meta": {
                "added": [
                  "v14.6.0",
                  "v12.19.0"
                ],
                "changes": [
                  {
                    "version": [
                      "v25.4.0",
                      "v24.14.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/60864",
                    "description": "Allow subpath imports that start with `#/`."
                  }
                ]
              },
              "desc": "<p>In addition to the <a href=\"#exports\"><code>\"exports\"</code></a> field, there is a package <code>\"imports\"</code> field\nto create private mappings that only apply to import specifiers from within the\npackage itself.</p>\n<p>Entries in the <code>\"imports\"</code> field must always start with <code>#</code> to ensure they are\ndisambiguated from external package specifiers.</p>\n<p>For example, the imports field can be used to gain the benefits of conditional\nexports for internal modules:</p>\n<pre><code class=\"language-json\">// package.json\n{\n  \"imports\": {\n    \"#dep\": {\n      \"node\": \"dep-node-native\",\n      \"default\": \"./dep-polyfill.js\"\n    }\n  },\n  \"dependencies\": {\n    \"dep-node-native\": \"^1.0.0\"\n  }\n}\n</code></pre>\n<p>where <code>import '#dep'</code> does not get the resolution of the external package\n<code>dep-node-native</code> (including its exports in turn), and instead gets the local\nfile <code>./dep-polyfill.js</code> relative to the package in other environments.</p>\n<p>Unlike the <code>\"exports\"</code> field, the <code>\"imports\"</code> field permits mapping to external\npackages.</p>\n<p>The resolution rules for the imports field are otherwise analogous to the\nexports field.</p>",
              "displayName": "Subpath imports"
            },
            {
              "textRaw": "Subpath patterns",
              "name": "subpath_patterns",
              "type": "module",
              "meta": {
                "added": [
                  "v14.13.0",
                  "v12.20.0"
                ],
                "changes": [
                  {
                    "version": [
                      "v16.10.0",
                      "v14.19.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/40041",
                    "description": "Support pattern trailers in \"imports\" field."
                  },
                  {
                    "version": [
                      "v16.9.0",
                      "v14.19.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/39635",
                    "description": "Support pattern trailers."
                  }
                ]
              },
              "desc": "<p>For packages with a small number of exports or imports, we recommend\nexplicitly listing each exports subpath entry. But for packages that have\nlarge numbers of subpaths, this might cause <code>package.json</code> bloat and\nmaintenance issues.</p>\n<p>For these use cases, subpath export patterns can be used instead:</p>\n<pre><code class=\"language-json\">// ./node_modules/es-module-package/package.json\n{\n  \"exports\": {\n    \"./features/*.js\": \"./src/features/*.js\"\n  },\n  \"imports\": {\n    \"#internal/*.js\": \"./src/internal/*.js\"\n  }\n}\n</code></pre>\n<p><strong><code>*</code> maps expose nested subpaths as it is a string replacement syntax\nonly.</strong></p>\n<p>All instances of <code>*</code> on the right hand side will then be replaced with this\nvalue, including if it contains any <code>/</code> separators.</p>\n<pre><code class=\"language-js\">import featureX from 'es-module-package/features/x.js';\n// Loads ./node_modules/es-module-package/src/features/x.js\n\nimport featureY from 'es-module-package/features/y/y.js';\n// Loads ./node_modules/es-module-package/src/features/y/y.js\n\nimport internalZ from '#internal/z.js';\n// Loads ./src/internal/z.js\n</code></pre>\n<p>This is a direct static matching and replacement without any special handling\nfor file extensions. Including the <code>\"*.js\"</code> on both sides of the mapping\nrestricts the exposed package exports to only JS files.</p>\n<p>The property of exports being statically enumerable is maintained with exports\npatterns since the individual exports for a package can be determined by\ntreating the right hand side target pattern as a <code>**</code> glob against the list of\nfiles within the package. Because <code>node_modules</code> paths are forbidden in exports\ntargets, this expansion is dependent on only the files of the package itself.</p>\n<p>To exclude private subfolders from patterns, <code>null</code> targets can be used:</p>\n<pre><code class=\"language-json\">// ./node_modules/es-module-package/package.json\n{\n  \"exports\": {\n    \"./features/*.js\": \"./src/features/*.js\",\n    \"./features/private-internal/*\": null\n  }\n}\n</code></pre>\n<pre><code class=\"language-js\">import featureInternal from 'es-module-package/features/private-internal/m.js';\n// Throws: ERR_PACKAGE_PATH_NOT_EXPORTED\n\nimport featureX from 'es-module-package/features/x.js';\n// Loads ./node_modules/es-module-package/src/features/x.js\n</code></pre>",
              "displayName": "Subpath patterns"
            },
            {
              "textRaw": "Conditional exports",
              "name": "conditional_exports",
              "type": "module",
              "meta": {
                "added": [
                  "v13.2.0",
                  "v12.16.0"
                ],
                "changes": [
                  {
                    "version": [
                      "v13.7.0",
                      "v12.16.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/31001",
                    "description": "Unflag conditional exports."
                  }
                ]
              },
              "desc": "<p>Conditional exports provide a way to map to different paths depending on\ncertain conditions. They are supported for both CommonJS and ES module imports.</p>\n<p>For example, a package that wants to provide different ES module exports for\n<code>require()</code> and <code>import</code> can be written:</p>\n<pre><code class=\"language-json\">// package.json\n{\n  \"exports\": {\n    \"import\": \"./index-module.js\",\n    \"require\": \"./index-require.cjs\"\n  },\n  \"type\": \"module\"\n}\n</code></pre>\n<p>Node.js implements the following conditions, listed in order from most\nspecific to least specific as conditions should be defined:</p>\n<ul>\n<li><code>\"node-addons\"</code> - similar to <code>\"node\"</code> and matches for any Node.js environment.\nThis condition can be used to provide an entry point which uses native C++\naddons as opposed to an entry point which is more universal and doesn't rely\non native addons. This condition can be disabled via the\n<a href=\"cli.html#--no-addons\"><code>--no-addons</code> flag</a>.</li>\n<li><code>\"node\"</code> - matches for any Node.js environment. Can be a CommonJS or ES\nmodule file. <em>In most cases explicitly calling out the Node.js platform is\nnot necessary.</em></li>\n<li><code>\"import\"</code> - matches when the package is loaded via <code>import</code> or\n<code>import()</code>, or via any top-level import or resolve operation by the\nECMAScript module loader. Applies regardless of the module format of the\ntarget file. <em>Always mutually exclusive with <code>\"require\"</code>.</em></li>\n<li><code>\"require\"</code> - matches when the package is loaded via <code>require()</code>. The\nreferenced file should be loadable with <code>require()</code> although the condition\nmatches regardless of the module format of the target file. Expected\nformats include CommonJS, JSON, native addons, and ES modules. <em>Always mutually\nexclusive with <code>\"import\"</code>.</em></li>\n<li><code>\"module-sync\"</code> - matches no matter the package is loaded via <code>import</code>,\n<code>import()</code> or <code>require()</code>. The format is expected to be ES modules that does\nnot contain top-level await in its module graph - if it does,\n<code>ERR_REQUIRE_ASYNC_MODULE</code> will be thrown when the module is <code>require()</code>-ed.</li>\n<li><code>\"default\"</code> - the generic fallback that always matches. Can be a CommonJS\nor ES module file. <em>This condition should always come last.</em></li>\n</ul>\n<p>Within the <a href=\"#exports\"><code>\"exports\"</code></a> object, key order is significant. During condition\nmatching, earlier entries have higher priority and take precedence over later\nentries. <em>The general rule is that conditions should be from most specific to\nleast specific in object order</em>.</p>\n<p>Using the <code>\"import\"</code> and <code>\"require\"</code> conditions can lead to some hazards,\nwhich are further explained in <a href=\"#dual-commonjses-module-packages\">the dual CommonJS/ES module packages section</a>.</p>\n<p>The <code>\"node-addons\"</code> condition can be used to provide an entry point which\nuses native C++ addons. However, this condition can be disabled via the\n<a href=\"cli.html#--no-addons\"><code>--no-addons</code> flag</a>. When using <code>\"node-addons\"</code>, it's recommended to treat\n<code>\"default\"</code> as an enhancement that provides a more universal entry point, e.g.\nusing WebAssembly instead of a native addon.</p>\n<p>Conditional exports can also be extended to exports subpaths, for example:</p>\n<pre><code class=\"language-json\">{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./feature.js\": {\n      \"node\": \"./feature-node.js\",\n      \"default\": \"./feature.js\"\n    }\n  }\n}\n</code></pre>\n<p>Defines a package where <code>require('pkg/feature.js')</code> and\n<code>import 'pkg/feature.js'</code> could provide different implementations between\nNode.js and other JS environments.</p>\n<p>When using environment branches, always include a <code>\"default\"</code> condition where\npossible. Providing a <code>\"default\"</code> condition ensures that any unknown JS\nenvironments are able to use this universal implementation, which helps avoid\nthese JS environments from having to pretend to be existing environments in\norder to support packages with conditional exports. For this reason, using\n<code>\"node\"</code> and <code>\"default\"</code> condition branches is usually preferable to using\n<code>\"node\"</code> and <code>\"browser\"</code> condition branches.</p>",
              "displayName": "Conditional exports"
            },
            {
              "textRaw": "Nested conditions",
              "name": "nested_conditions",
              "type": "module",
              "desc": "<p>In addition to direct mappings, Node.js also supports nested condition objects.</p>\n<p>For example, to define a package that only has dual mode entry points for\nuse in Node.js but not the browser:</p>\n<pre><code class=\"language-json\">{\n  \"exports\": {\n    \"node\": {\n      \"import\": \"./feature-node.mjs\",\n      \"require\": \"./feature-node.cjs\"\n    },\n    \"default\": \"./feature.mjs\"\n  }\n}\n</code></pre>\n<p>Conditions continue to be matched in order as with flat conditions. If\na nested condition does not have any mapping it will continue checking\nthe remaining conditions of the parent condition. In this way nested\nconditions behave analogously to nested JavaScript <code>if</code> statements.</p>",
              "displayName": "Nested conditions"
            },
            {
              "textRaw": "Resolving user conditions",
              "name": "resolving_user_conditions",
              "type": "module",
              "meta": {
                "added": [
                  "v14.9.0",
                  "v12.19.0"
                ],
                "changes": []
              },
              "desc": "<p>When running Node.js, custom user conditions can be added with the\n<code>--conditions</code> flag:</p>\n<pre><code class=\"language-bash\">node --conditions=development index.js\n</code></pre>\n<p>which would then resolve the <code>\"development\"</code> condition in package imports and\nexports, while resolving the existing <code>\"node\"</code>, <code>\"node-addons\"</code>, <code>\"default\"</code>,\n<code>\"import\"</code>, and <code>\"require\"</code> conditions as appropriate.</p>\n<p>Any number of custom conditions can be set with repeat flags.</p>\n<p>Typical conditions should only contain alphanumerical characters,\nusing \":\", \"-\", or \"=\" as separators if necessary. Anything else may run\ninto compability issues outside of node.</p>\n<p>In node, conditions have very few restrictions, but specifically these include:</p>\n<ol>\n<li>They must contain at least one character.</li>\n<li>They cannot start with \".\" since they may appear in places that also\nallow relative paths.</li>\n<li>They cannot contain \",\" since they may be parsed as a comma-separated\nlist by some CLI tools.</li>\n<li>They cannot be integer property keys like \"10\" since that can have\nunexpected effects on property key ordering for JS objects.</li>\n</ol>",
              "displayName": "Resolving user conditions"
            },
            {
              "textRaw": "Community Conditions Definitions",
              "name": "community_conditions_definitions",
              "type": "module",
              "desc": "<p>Condition strings other than the <code>\"import\"</code>, <code>\"require\"</code>, <code>\"node\"</code>, <code>\"module-sync\"</code>,\n<code>\"node-addons\"</code> and <code>\"default\"</code> conditions\n<a href=\"#conditional-exports\">implemented in Node.js core</a> are ignored by default.</p>\n<p>Other platforms may implement other conditions and user conditions can be\nenabled in Node.js via the <a href=\"#resolving-user-conditions\"><code>--conditions</code> / <code>-C</code> flag</a>.</p>\n<p>Since custom package conditions require clear definitions to ensure correct\nusage, a list of common known package conditions and their strict definitions\nis provided below to assist with ecosystem coordination.</p>\n<ul>\n<li><code>\"types\"</code> - can be used by typing systems to resolve the typing file for\nthe given export. <em>This condition should always be included first.</em></li>\n<li><code>\"browser\"</code> - any web browser environment.</li>\n<li><code>\"development\"</code> - can be used to define a development-only environment\nentry point, for example to provide additional debugging context such as\nbetter error messages when running in a development mode. <em>Must always be\nmutually exclusive with <code>\"production\"</code>.</em></li>\n<li><code>\"production\"</code> - can be used to define a production environment entry\npoint. <em>Must always be mutually exclusive with <code>\"development\"</code>.</em></li>\n</ul>\n<p>For other runtimes, platform-specific condition key definitions are maintained\nby the <a href=\"https://wintercg.org/\">WinterCG</a> in the <a href=\"https://runtime-keys.proposal.wintercg.org/\">Runtime Keys</a> proposal specification.</p>\n<p>New conditions definitions may be added to this list by creating a pull request\nto the <a href=\"https://github.com/nodejs/node/blob/HEAD/doc/api/packages.md#conditions-definitions\">Node.js documentation for this section</a>. The requirements for listing\na new condition definition here are that:</p>\n<ul>\n<li>The definition should be clear and unambiguous for all implementers.</li>\n<li>The use case for why the condition is needed should be clearly justified.</li>\n<li>There should exist sufficient existing implementation usage.</li>\n<li>The condition name should not conflict with another condition definition or\ncondition in wide usage.</li>\n<li>The listing of the condition definition should provide a coordination\nbenefit to the ecosystem that wouldn't otherwise be possible. For example,\nthis would not necessarily be the case for company-specific or\napplication-specific conditions.</li>\n<li>The condition should be such that a Node.js user would expect it to be in\nNode.js core documentation. The <code>\"types\"</code> condition is a good example: It\ndoesn't really belong in the <a href=\"https://runtime-keys.proposal.wintercg.org/\">Runtime Keys</a> proposal but is a good fit\nhere in the Node.js docs.</li>\n</ul>\n<p>The above definitions may be moved to a dedicated conditions registry in due\ncourse.</p>",
              "displayName": "Community Conditions Definitions"
            },
            {
              "textRaw": "Self-referencing a package using its name",
              "name": "self-referencing_a_package_using_its_name",
              "type": "module",
              "meta": {
                "added": [
                  "v13.1.0",
                  "v12.16.0"
                ],
                "changes": [
                  {
                    "version": [
                      "v13.6.0",
                      "v12.16.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/31002",
                    "description": "Unflag self-referencing a package using its name."
                  }
                ]
              },
              "desc": "<p>Within a package, the values defined in the package's\n<code>package.json</code> <a href=\"#exports\"><code>\"exports\"</code></a> field can be referenced via the package's name.\nFor example, assuming the <code>package.json</code> is:</p>\n<pre><code class=\"language-json\">// package.json\n{\n  \"name\": \"a-package\",\n  \"exports\": {\n    \".\": \"./index.mjs\",\n    \"./foo.js\": \"./foo.js\"\n  }\n}\n</code></pre>\n<p>Then any module <em>in that package</em> can reference an export in the package itself:</p>\n<pre><code class=\"language-js\">// ./a-module.mjs\nimport { something } from 'a-package'; // Imports \"something\" from ./index.mjs.\n</code></pre>\n<p>Self-referencing is available only if <code>package.json</code> has <a href=\"#exports\"><code>\"exports\"</code></a>, and\nwill allow importing only what that <a href=\"#exports\"><code>\"exports\"</code></a> (in the <code>package.json</code>)\nallows. So the code below, given the previous package, will generate a runtime\nerror:</p>\n<pre><code class=\"language-js\">// ./another-module.mjs\n\n// Imports \"another\" from ./m.mjs. Fails because\n// the \"package.json\" \"exports\" field\n// does not provide an export named \"./m.mjs\".\nimport { another } from 'a-package/m.mjs';\n</code></pre>\n<p>Self-referencing is also available when using <code>require</code>, both in an ES module,\nand in a CommonJS one. For example, this code will also work:</p>\n<pre><code class=\"language-cjs\">// ./a-module.js\nconst { something } = require('a-package/foo.js'); // Loads from ./foo.js.\n</code></pre>\n<p>Finally, self-referencing also works with scoped packages. For example, this\ncode will also work:</p>\n<pre><code class=\"language-json\">// package.json\n{\n  \"name\": \"@my/package\",\n  \"exports\": \"./index.js\"\n}\n</code></pre>\n<pre><code class=\"language-cjs\">// ./index.js\nmodule.exports = 42;\n</code></pre>\n<pre><code class=\"language-cjs\">// ./other.js\nconsole.log(require('@my/package'));\n</code></pre>\n<pre><code class=\"language-console\">$ node other.js\n42\n</code></pre>",
              "displayName": "Self-referencing a package using its name"
            }
          ],
          "displayName": "Package entry points"
        },
        {
          "textRaw": "Dual CommonJS/ES module packages",
          "name": "dual_commonjs/es_module_packages",
          "type": "misc",
          "desc": "<p>See <a href=\"https://github.com/nodejs/package-examples\">the package examples repository</a> for details.</p>",
          "displayName": "Dual CommonJS/ES module packages"
        },
        {
          "textRaw": "Node.js `package.json` field definitions",
          "name": "node.js_`package.json`_field_definitions",
          "type": "misc",
          "desc": "<p>This section describes the fields used by the Node.js runtime. Other tools (such\nas <a href=\"https://docs.npmjs.com/cli/v8/configuring-npm/package-json\">npm</a>) use\nadditional fields which are ignored by Node.js and not documented here.</p>\n<p>The following fields in <code>package.json</code> files are used in Node.js:</p>\n<ul>\n<li><a href=\"#name\"><code>\"name\"</code></a> - Relevant when using named imports within a package. Also used\nby package managers as the name of the package.</li>\n<li><a href=\"#main\"><code>\"main\"</code></a> - The default module when loading the package, if exports is not\nspecified, and in versions of Node.js prior to the introduction of exports.</li>\n<li><a href=\"#type\"><code>\"type\"</code></a> - The package type determining whether to load <code>.js</code> files as\nCommonJS or ES modules.</li>\n<li><a href=\"#exports\"><code>\"exports\"</code></a> - Package exports and conditional exports. When present,\nlimits which submodules can be loaded from within the package.</li>\n<li><a href=\"#imports\"><code>\"imports\"</code></a> - Package imports, for use by modules within the package\nitself.</li>\n</ul>",
          "modules": [
            {
              "textRaw": "`\"name\"`",
              "name": "`\"name\"`",
              "type": "module",
              "meta": {
                "added": [
                  "v13.1.0",
                  "v12.16.0"
                ],
                "changes": [
                  {
                    "version": [
                      "v13.6.0",
                      "v12.16.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/31002",
                    "description": "Remove the `--experimental-resolve-self` option."
                  }
                ]
              },
              "desc": "<ul>\n<li>Type: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a></li>\n</ul>\n<pre><code class=\"language-json\">{\n  \"name\": \"package-name\"\n}\n</code></pre>\n<p>The <code>\"name\"</code> field defines your package's name. Publishing to the\n<em>npm</em> registry requires a name that satisfies\n<a href=\"https://docs.npmjs.com/files/package.json#name\">certain requirements</a>.</p>\n<p>The <code>\"name\"</code> field can be used in addition to the <a href=\"#exports\"><code>\"exports\"</code></a> field to\n<a href=\"#self-referencing-a-package-using-its-name\">self-reference</a> a package using its name.</p>",
              "displayName": "`\"name\"`"
            },
            {
              "textRaw": "`\"main\"`",
              "name": "`\"main\"`",
              "type": "module",
              "meta": {
                "added": [
                  "v0.4.0"
                ],
                "changes": []
              },
              "desc": "<ul>\n<li>Type: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a></li>\n</ul>\n<pre><code class=\"language-json\">{\n  \"main\": \"./index.js\"\n}\n</code></pre>\n<p>The <code>\"main\"</code> field defines the entry point of a package when imported by name\nvia a <code>node_modules</code> lookup.  Its value is a path.</p>\n<p>The <a href=\"#exports\"><code>\"exports\"</code></a> field, if it exists, takes precedence over the\n<code>\"main\"</code> field when importing the package by name.</p>\n<p>It also defines the script that is used when the <a href=\"modules.html#folders-as-modules\">package directory is loaded\nvia <code>require()</code></a>.</p>\n<pre><code class=\"language-cjs\">// This resolves to ./path/to/directory/index.js.\nrequire('./path/to/directory');\n</code></pre>",
              "displayName": "`\"main\"`"
            },
            {
              "textRaw": "`\"type\"`",
              "name": "`\"type\"`",
              "type": "module",
              "meta": {
                "added": [
                  "v12.0.0"
                ],
                "changes": [
                  {
                    "version": [
                      "v13.2.0",
                      "v12.17.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/29866",
                    "description": "Unflag `--experimental-modules`."
                  }
                ]
              },
              "desc": "<ul>\n<li>Type: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a></li>\n</ul>\n<p>The <code>\"type\"</code> field defines the module format that Node.js uses for all\n<code>.js</code> files that have that <code>package.json</code> file as their nearest parent.</p>\n<p>Files ending with <code>.js</code> are loaded as ES modules when the nearest parent\n<code>package.json</code> file contains a top-level field <code>\"type\"</code> with a value of\n<code>\"module\"</code>.</p>\n<p>The nearest parent <code>package.json</code> is defined as the first <code>package.json</code> found\nwhen searching in the current folder, that folder's parent, and so on up\nuntil a node_modules folder or the volume root is reached.</p>\n<pre><code class=\"language-json\">// package.json\n{\n  \"type\": \"module\"\n}\n</code></pre>\n<pre><code class=\"language-bash\"># In same folder as preceding package.json\nnode my-app.js # Runs as ES module\n</code></pre>\n<p>If the nearest parent <code>package.json</code> lacks a <code>\"type\"</code> field, or contains\n<code>\"type\": \"commonjs\"</code>, <code>.js</code> files are treated as <a href=\"modules.html\">CommonJS</a>. If the volume\nroot is reached and no <code>package.json</code> is found, <code>.js</code> files are treated as\n<a href=\"modules.html\">CommonJS</a>.</p>\n<p><code>import</code> statements of <code>.js</code> files are treated as ES modules if the nearest\nparent <code>package.json</code> contains <code>\"type\": \"module\"</code>.</p>\n<pre><code class=\"language-js\">// my-app.js, part of the same example as above\nimport './startup.js'; // Loaded as ES module because of package.json\n</code></pre>\n<p>Regardless of the value of the <code>\"type\"</code> field, <code>.mjs</code> files are always treated\nas ES modules and <code>.cjs</code> files are always treated as CommonJS.</p>",
              "displayName": "`\"type\"`"
            },
            {
              "textRaw": "`\"exports\"`",
              "name": "`\"exports\"`",
              "type": "module",
              "meta": {
                "added": [
                  "v12.7.0"
                ],
                "changes": [
                  {
                    "version": [
                      "v14.13.0",
                      "v12.20.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/34718",
                    "description": "Add support for `\"exports\"` patterns."
                  },
                  {
                    "version": [
                      "v13.7.0",
                      "v12.17.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/29866",
                    "description": "Unflag conditional exports."
                  },
                  {
                    "version": [
                      "v13.7.0",
                      "v12.16.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/31008",
                    "description": "Implement logical conditional exports ordering."
                  },
                  {
                    "version": [
                      "v13.7.0",
                      "v12.16.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/31001",
                    "description": "Remove the `--experimental-conditional-exports` option. In 12.16.0, conditional exports are still behind `--experimental-modules`."
                  },
                  {
                    "version": [
                      "v13.2.0",
                      "v12.16.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/29978",
                    "description": "Implement conditional exports."
                  }
                ]
              },
              "desc": "<ul>\n<li>Type: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\"><code>&#x3C;Object></code></a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string[]></code></a></li>\n</ul>\n<pre><code class=\"language-json\">{\n  \"exports\": \"./index.js\"\n}\n</code></pre>\n<p>The <code>\"exports\"</code> field allows defining the <a href=\"#package-entry-points\">entry points</a> of a package when\nimported by name loaded either via a <code>node_modules</code> lookup or a\n<a href=\"#self-referencing-a-package-using-its-name\">self-reference</a> to its own name. It is supported in Node.js 12+ as an\nalternative to the <a href=\"#main\"><code>\"main\"</code></a> that can support defining <a href=\"#subpath-exports\">subpath exports</a>\nand <a href=\"#conditional-exports\">conditional exports</a> while encapsulating internal unexported modules.</p>\n<p><a href=\"#conditional-exports\">Conditional Exports</a> can also be used within <code>\"exports\"</code> to define different\npackage entry points per environment, including whether the package is\nreferenced via <code>require</code> or via <code>import</code>.</p>\n<p>All paths defined in the <code>\"exports\"</code> must be relative file URLs starting with\n<code>./</code>.</p>",
              "displayName": "`\"exports\"`"
            },
            {
              "textRaw": "`\"imports\"`",
              "name": "`\"imports\"`",
              "type": "module",
              "meta": {
                "added": [
                  "v14.6.0",
                  "v12.19.0"
                ],
                "changes": []
              },
              "desc": "<ul>\n<li>Type: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\"><code>&#x3C;Object></code></a></li>\n</ul>\n<pre><code class=\"language-json\">// package.json\n{\n  \"imports\": {\n    \"#dep\": {\n      \"node\": \"dep-node-native\",\n      \"default\": \"./dep-polyfill.js\"\n    }\n  },\n  \"dependencies\": {\n    \"dep-node-native\": \"^1.0.0\"\n  }\n}\n</code></pre>\n<p>Entries in the imports field must be strings starting with <code>#</code>.</p>\n<p>Package imports permit mapping to external packages.</p>\n<p>This field defines <a href=\"#subpath-imports\">subpath imports</a> for the current package.</p>",
              "displayName": "`\"imports\"`"
            }
          ],
          "displayName": "Node.js `package.json` field definitions"
        }
      ]
    }
  ]
}