{
  "type": "module",
  "source": "doc/api/esm.md",
  "introduced_in": "v8.5.0",
  "meta": {
    "added": [
      "v8.5.0"
    ],
    "changes": [
      {
        "version": [
          "v23.1.0",
          "v22.12.0",
          "v20.18.3",
          "v18.20.5"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/55333",
        "description": "Import attributes are no longer experimental."
      },
      {
        "version": "v22.0.0",
        "pr-url": "https://github.com/nodejs/node/pull/52104",
        "description": "Drop support for import assertions."
      },
      {
        "version": [
          "v21.0.0",
          "v20.10.0",
          "v18.20.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/50140",
        "description": "Add experimental support for import attributes."
      },
      {
        "version": [
          "v20.0.0",
          "v18.19.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/44710",
        "description": "Module customization hooks are executed off the main thread."
      },
      {
        "version": [
          "v18.6.0",
          "v16.17.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/42623",
        "description": "Add support for chaining module customization hooks."
      },
      {
        "version": [
          "v17.1.0",
          "v16.14.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/40250",
        "description": "Add experimental support for import assertions."
      },
      {
        "version": [
          "v17.0.0",
          "v16.12.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/37468",
        "description": "Consolidate customization hooks, removed `getFormat`, `getSource`, `transformSource`, and `getGlobalPreloadCode` hooks added `load` and `globalPreload` hooks allowed returning `format` from either `resolve` or `load` hooks."
      },
      {
        "version": [
          "v15.3.0",
          "v14.17.0",
          "v12.22.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/35781",
        "description": "Stabilize modules implementation."
      },
      {
        "version": [
          "v14.13.0",
          "v12.20.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/35249",
        "description": "Support for detection of CommonJS named exports."
      },
      {
        "version": "v14.8.0",
        "pr-url": "https://github.com/nodejs/node/pull/34558",
        "description": "Unflag Top-Level Await."
      },
      {
        "version": [
          "v14.0.0",
          "v13.14.0",
          "v12.20.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/31974",
        "description": "Remove experimental modules warning."
      },
      {
        "version": [
          "v13.2.0",
          "v12.17.0"
        ],
        "pr-url": "https://github.com/nodejs/node/pull/29866",
        "description": "Loading ECMAScript modules no longer requires a command-line flag."
      },
      {
        "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."
      }
    ]
  },
  "stability": 2,
  "stabilityText": "Stable",
  "properties": [
    {
      "textRaw": "Type: {Object}",
      "name": "meta",
      "type": "Object",
      "desc": "<p>The <code>import.meta</code> meta property is an <code>Object</code> that contains the following\nproperties. It is only supported in ES modules.</p>",
      "properties": [
        {
          "textRaw": "Type: {string} The directory name of the current module.",
          "name": "dirname",
          "type": "string",
          "meta": {
            "added": [
              "v21.2.0",
              "v20.11.0"
            ],
            "changes": [
              {
                "version": [
                  "v24.0.0",
                  "v22.16.0"
                ],
                "pr-url": "https://github.com/nodejs/node/pull/58011",
                "description": "This property is no longer experimental."
              }
            ]
          },
          "desc": "<p>This is the same as the <a href=\"path.html#pathdirnamepath\"><code>path.dirname()</code></a> of the <a href=\"#importmetafilename\"><code>import.meta.filename</code></a>.</p>\n<blockquote>\n<p><strong>Caveat</strong>: only present on <code>file:</code> modules.</p>\n</blockquote>",
          "shortDesc": "The directory name of the current module."
        },
        {
          "textRaw": "Type: {string} The full absolute path and filename of the current module, with symlinks resolved.",
          "name": "filename",
          "type": "string",
          "meta": {
            "added": [
              "v21.2.0",
              "v20.11.0"
            ],
            "changes": [
              {
                "version": [
                  "v24.0.0",
                  "v22.16.0"
                ],
                "pr-url": "https://github.com/nodejs/node/pull/58011",
                "description": "This property is no longer experimental."
              }
            ]
          },
          "desc": "<p>This is the same as the <a href=\"url.html#urlfileurltopathurl-options\"><code>url.fileURLToPath()</code></a> of the <a href=\"#importmetaurl\"><code>import.meta.url</code></a>.</p>\n<blockquote>\n<p><strong>Caveat</strong> only local modules support this property. Modules not using the\n<code>file:</code> protocol will not provide it.</p>\n</blockquote>",
          "shortDesc": "The full absolute path and filename of the current module, with symlinks resolved."
        },
        {
          "textRaw": "Type: {string} The absolute `file:` URL of the module.",
          "name": "url",
          "type": "string",
          "desc": "<p>This is defined exactly the same as it is in browsers providing the URL of the\ncurrent module file.</p>\n<p>This enables useful patterns such as relative file loading:</p>\n<pre><code class=\"language-js\">import { readFileSync } from 'node:fs';\nconst buffer = readFileSync(new URL('./data.proto', import.meta.url));\n</code></pre>",
          "shortDesc": "The absolute `file:` URL of the module."
        },
        {
          "textRaw": "Type: {boolean} `true` when the current module is the entry point of the current process; `false` otherwise.",
          "name": "main",
          "type": "boolean",
          "meta": {
            "added": [
              "v24.2.0",
              "v22.18.0"
            ],
            "changes": []
          },
          "stability": 1,
          "stabilityText": "Early development",
          "desc": "<p>Equivalent to <code>require.main === module</code> in CommonJS.</p>\n<p>Analogous to Python's <code>__name__ == \"__main__\"</code>.</p>\n<pre><code class=\"language-js\">export function foo() {\n  return 'Hello, world';\n}\n\nfunction main() {\n  const message = foo();\n  console.log(message);\n}\n\nif (import.meta.main) main();\n// `foo` can be imported from another module without possible side-effects from `main`\n</code></pre>",
          "shortDesc": "`true` when the current module is the entry point of the current process; `false` otherwise."
        }
      ],
      "methods": [
        {
          "textRaw": "`import.meta.resolve(specifier)`",
          "name": "resolve",
          "type": "method",
          "meta": {
            "added": [
              "v13.9.0",
              "v12.16.2"
            ],
            "changes": [
              {
                "version": [
                  "v20.6.0",
                  "v18.19.0"
                ],
                "pr-url": "https://github.com/nodejs/node/pull/49028",
                "description": "No longer behind `--experimental-import-meta-resolve` CLI flag, except for the non-standard `parentURL` parameter."
              },
              {
                "version": [
                  "v20.6.0",
                  "v18.19.0"
                ],
                "pr-url": "https://github.com/nodejs/node/pull/49038",
                "description": "This API no longer throws when targeting `file:` URLs that do not map to an existing file on the local FS."
              },
              {
                "version": [
                  "v20.0.0",
                  "v18.19.0"
                ],
                "pr-url": "https://github.com/nodejs/node/pull/44710",
                "description": "This API now returns a string synchronously instead of a Promise."
              },
              {
                "version": [
                  "v16.2.0",
                  "v14.18.0"
                ],
                "pr-url": "https://github.com/nodejs/node/pull/38587",
                "description": "Add support for WHATWG `URL` object to `parentURL` parameter."
              }
            ]
          },
          "stability": 1.2,
          "stabilityText": "Release candidate",
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`specifier` {string} The module specifier to resolve relative to the current module.",
                  "name": "specifier",
                  "type": "string",
                  "desc": "The module specifier to resolve relative to the current module."
                }
              ],
              "return": {
                "textRaw": "Returns: {string} The absolute URL string that the specifier would resolve to.",
                "name": "return",
                "type": "string",
                "desc": "The absolute URL string that the specifier would resolve to."
              }
            }
          ],
          "desc": "<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve\"><code>import.meta.resolve</code></a> is a module-relative resolution function scoped to\neach module, returning the URL string.</p>\n<pre><code class=\"language-js\">const dependencyAsset = import.meta.resolve('component-lib/asset.css');\n// file:///app/node_modules/component-lib/asset.css\nimport.meta.resolve('./dep.js');\n// file:///app/dep.js\n</code></pre>\n<p>All features of the Node.js module resolution are supported. Dependency\nresolutions are subject to the permitted exports resolutions within the package.</p>\n<p><strong>Caveats</strong>:</p>\n<ul>\n<li>This can result in synchronous file-system operations, which\ncan impact performance similarly to <code>require.resolve</code>.</li>\n<li>This feature is not available within custom loaders (it would\ncreate a deadlock).</li>\n</ul>\n<p><strong>Non-standard API</strong>:</p>\n<p>When using the <code>--experimental-import-meta-resolve</code> flag, that function accepts\na second argument:</p>\n<ul>\n<li><code>parent</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> | <a href=\"url.html#the-whatwg-url-api\"><code>&#x3C;URL></code></a> An optional absolute parent module URL to resolve from. <strong>Default:</strong> <code>import.meta.url</code></li>\n</ul>"
        }
      ]
    }
  ],
  "miscs": [
    {
      "textRaw": "Modules: ECMAScript modules",
      "name": "Modules: ECMAScript modules",
      "introduced_in": "v8.5.0",
      "type": "misc",
      "meta": {
        "added": [
          "v8.5.0"
        ],
        "changes": [
          {
            "version": [
              "v23.1.0",
              "v22.12.0",
              "v20.18.3",
              "v18.20.5"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/55333",
            "description": "Import attributes are no longer experimental."
          },
          {
            "version": "v22.0.0",
            "pr-url": "https://github.com/nodejs/node/pull/52104",
            "description": "Drop support for import assertions."
          },
          {
            "version": [
              "v21.0.0",
              "v20.10.0",
              "v18.20.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/50140",
            "description": "Add experimental support for import attributes."
          },
          {
            "version": [
              "v20.0.0",
              "v18.19.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/44710",
            "description": "Module customization hooks are executed off the main thread."
          },
          {
            "version": [
              "v18.6.0",
              "v16.17.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/42623",
            "description": "Add support for chaining module customization hooks."
          },
          {
            "version": [
              "v17.1.0",
              "v16.14.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/40250",
            "description": "Add experimental support for import assertions."
          },
          {
            "version": [
              "v17.0.0",
              "v16.12.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/37468",
            "description": "Consolidate customization hooks, removed `getFormat`, `getSource`, `transformSource`, and `getGlobalPreloadCode` hooks added `load` and `globalPreload` hooks allowed returning `format` from either `resolve` or `load` hooks."
          },
          {
            "version": [
              "v15.3.0",
              "v14.17.0",
              "v12.22.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/35781",
            "description": "Stabilize modules implementation."
          },
          {
            "version": [
              "v14.13.0",
              "v12.20.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/35249",
            "description": "Support for detection of CommonJS named exports."
          },
          {
            "version": "v14.8.0",
            "pr-url": "https://github.com/nodejs/node/pull/34558",
            "description": "Unflag Top-Level Await."
          },
          {
            "version": [
              "v14.0.0",
              "v13.14.0",
              "v12.20.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/31974",
            "description": "Remove experimental modules warning."
          },
          {
            "version": [
              "v13.2.0",
              "v12.17.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/29866",
            "description": "Loading ECMAScript modules no longer requires a command-line flag."
          },
          {
            "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."
          }
        ]
      },
      "stability": 2,
      "stabilityText": "Stable",
      "miscs": [
        {
          "textRaw": "Introduction",
          "name": "introduction",
          "type": "misc",
          "desc": "<p>ECMAScript modules are <a href=\"https://tc39.github.io/ecma262/#sec-modules\">the official standard format</a> to package JavaScript\ncode for reuse. Modules are defined using a variety of <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import\"><code>import</code></a> and\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export\"><code>export</code></a> statements.</p>\n<p>The following example of an ES module exports a function:</p>\n<pre><code class=\"language-js\">// addTwo.mjs\nfunction addTwo(num) {\n  return num + 2;\n}\n\nexport { addTwo };\n</code></pre>\n<p>The following example of an ES module imports the function from <code>addTwo.mjs</code>:</p>\n<pre><code class=\"language-js\">// app.mjs\nimport { addTwo } from './addTwo.mjs';\n\n// Prints: 6\nconsole.log(addTwo(4));\n</code></pre>\n<p>Node.js fully supports ECMAScript modules as they are currently specified and\nprovides interoperability between them and its original module format,\n<a href=\"modules.html\">CommonJS</a>.</p>\n<p><i id=\"esm_package_json_type_field\"></i><i id=\"esm_package_scope_and_file_extensions\"></i><i id=\"esm_input_type_flag\"></i></p>",
          "displayName": "Introduction"
        },
        {
          "textRaw": "Enabling",
          "name": "Enabling",
          "type": "misc",
          "desc": "<p>Node.js has two module systems: <a href=\"modules.html\">CommonJS</a> modules and ECMAScript modules.</p>\n<p>Authors can tell Node.js to interpret JavaScript as an ES module via the <code>.mjs</code>\nfile extension, the <code>package.json</code> <a href=\"packages.html#type\"><code>\"type\"</code></a> field with a value <code>\"module\"</code>,\nor the <a href=\"cli.html#--input-typetype\"><code>--input-type</code></a> flag with a value of <code>\"module\"</code>. These are explicit\nmarkers of code being intended to run as an ES module.</p>\n<p>Inversely, authors can explicitly tell Node.js to interpret JavaScript as\nCommonJS via the <code>.cjs</code> file extension, the <code>package.json</code> <a href=\"packages.html#type\"><code>\"type\"</code></a> field\nwith a value <code>\"commonjs\"</code>, or the <a href=\"cli.html#--input-typetype\"><code>--input-type</code></a> flag with a value of\n<code>\"commonjs\"</code>.</p>\n<p>When code lacks explicit markers for either module system, Node.js will inspect\nthe source code of a module to look for ES module syntax. If such syntax is\nfound, Node.js will run the code as an ES module; otherwise it will run the\nmodule as CommonJS. See <a href=\"packages.html#determining-module-system\">Determining module system</a> for more details.</p>\n<p><i id=\"esm_package_entry_points\"></i><i id=\"esm_main_entry_point_export\"></i><i id=\"esm_subpath_exports\"></i><i id=\"esm_package_exports_fallbacks\"></i><i id=\"esm_exports_sugar\"></i><i id=\"esm_conditional_exports\"></i><i id=\"esm_nested_conditions\"></i><i id=\"esm_self_referencing_a_package_using_its_name\"></i><i id=\"esm_internal_package_imports\"></i><i id=\"esm_dual_commonjs_es_module_packages\"></i><i id=\"esm_dual_package_hazard\"></i><i id=\"esm_writing_dual_packages_while_avoiding_or_minimizing_hazards\"></i><i id=\"esm_approach_1_use_an_es_module_wrapper\"></i><i id=\"esm_approach_2_isolate_state\"></i></p>"
        },
        {
          "textRaw": "Packages",
          "name": "packages",
          "type": "misc",
          "desc": "<p>This section was moved to <a href=\"packages.html\">Modules: Packages</a>.</p>",
          "displayName": "Packages"
        },
        {
          "textRaw": "`import` Specifiers",
          "name": "`import`_specifiers",
          "type": "misc",
          "modules": [
            {
              "textRaw": "Terminology",
              "name": "terminology",
              "type": "module",
              "desc": "<p>The <em>specifier</em> of an <code>import</code> statement is the string after the <code>from</code> keyword,\ne.g. <code>'node:path'</code> in <code>import { sep } from 'node:path'</code>. Specifiers are also\nused in <code>export from</code> statements, and as the argument to an <code>import()</code>\nexpression.</p>\n<p>There are three types of specifiers:</p>\n<ul>\n<li>\n<p><em>Relative specifiers</em> like <code>'./startup.js'</code> or <code>'../config.mjs'</code>. They refer\nto a path relative to the location of the importing file. <em>The file extension\nis always necessary for these.</em></p>\n</li>\n<li>\n<p><em>Bare specifiers</em> like <code>'some-package'</code> or <code>'some-package/shuffle'</code>. They can\nrefer to the main entry point of a package by the package name, or a\nspecific feature module within a package prefixed by the package name as per\nthe examples respectively. <em>Including the file extension is only necessary\nfor packages without an <a href=\"packages.html#exports\"><code>\"exports\"</code></a> field.</em></p>\n</li>\n<li>\n<p><em>Absolute specifiers</em> like <code>'file:///opt/nodejs/config.js'</code>. They refer\ndirectly and explicitly to a full path.</p>\n</li>\n</ul>\n<p>Bare specifier resolutions are handled by the <a href=\"#resolution-algorithm-specification\">Node.js module\nresolution and loading algorithm</a>.\nAll other specifier resolutions are always only resolved with\nthe standard relative <a href=\"https://url.spec.whatwg.org/\">URL</a> resolution semantics.</p>\n<p>Like in CommonJS, module files within packages can be accessed by appending a\npath to the package name unless the package's <a href=\"packages.html#nodejs-packagejson-field-definitions\"><code>package.json</code></a> contains an\n<a href=\"packages.html#exports\"><code>\"exports\"</code></a> field, in which case files within packages can only be accessed\nvia the paths defined in <a href=\"packages.html#exports\"><code>\"exports\"</code></a>.</p>\n<p>For details on these package resolution rules that apply to bare specifiers in\nthe Node.js module resolution, see the <a href=\"packages.html\">packages documentation</a>.</p>",
              "displayName": "Terminology"
            },
            {
              "textRaw": "Mandatory file extensions",
              "name": "mandatory_file_extensions",
              "type": "module",
              "desc": "<p>A file extension must be provided when using the <code>import</code> keyword to resolve\nrelative or absolute specifiers. Directory indexes (e.g. <code>'./startup/index.js'</code>)\nmust also be fully specified.</p>\n<p>This behavior matches how <code>import</code> behaves in browser environments, assuming a\ntypically configured server.</p>",
              "displayName": "Mandatory file extensions"
            },
            {
              "textRaw": "URLs",
              "name": "urls",
              "type": "module",
              "desc": "<p>ES modules are resolved and cached as URLs. This means that special characters\nmust be <a href=\"url.html#percent-encoding-in-urls\">percent-encoded</a>, such as <code>#</code> with <code>%23</code> and <code>?</code> with <code>%3F</code>.</p>\n<p><code>file:</code>, <code>node:</code>, and <code>data:</code> URL schemes are supported. A specifier like\n<code>'https://example.com/app.js'</code> is not supported natively in Node.js unless using\na <a href=\"module.html#import-from-https\">custom HTTPS loader</a>.</p>",
              "modules": [
                {
                  "textRaw": "`file:` URLs",
                  "name": "`file:`_urls",
                  "type": "module",
                  "desc": "<p>Modules are loaded multiple times if the <code>import</code> specifier used to resolve\nthem has a different query or fragment.</p>\n<pre><code class=\"language-js\">import './foo.mjs?query=1'; // loads ./foo.mjs with query of \"?query=1\"\nimport './foo.mjs?query=2'; // loads ./foo.mjs with query of \"?query=2\"\n</code></pre>\n<p>The volume root may be referenced via <code>/</code>, <code>//</code>, or <code>file:///</code>. Given the\ndifferences between <a href=\"https://url.spec.whatwg.org/\">URL</a> and path resolution (such as percent encoding\ndetails), it is recommended to use <a href=\"url.html#urlpathtofileurlpath-options\">url.pathToFileURL</a> when importing a path.</p>",
                  "displayName": "`file:` URLs"
                },
                {
                  "textRaw": "`data:` imports",
                  "name": "`data:`_imports",
                  "type": "module",
                  "meta": {
                    "added": [
                      "v12.10.0"
                    ],
                    "changes": []
                  },
                  "desc": "<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data\"><code>data:</code> URLs</a> are supported for importing with the following MIME types:</p>\n<ul>\n<li><code>text/javascript</code> for ES modules</li>\n<li><code>application/json</code> for JSON</li>\n<li><code>application/wasm</code> for Wasm</li>\n</ul>\n<pre><code class=\"language-js\">import 'data:text/javascript,console.log(\"hello!\");';\nimport _ from 'data:application/json,\"world!\"' with { type: 'json' };\n</code></pre>\n<p><code>data:</code> URLs only resolve <a href=\"#terminology\">bare specifiers</a> for builtin modules\nand <a href=\"#terminology\">absolute specifiers</a>. Resolving\n<a href=\"#terminology\">relative specifiers</a> does not work because <code>data:</code> is not a\n<a href=\"https://url.spec.whatwg.org/#special-scheme\">special scheme</a>. For example, attempting to load <code>./foo</code>\nfrom <code>data:text/javascript,import \"./foo\";</code> fails to resolve because there\nis no concept of relative resolution for <code>data:</code> URLs.</p>",
                  "displayName": "`data:` imports"
                },
                {
                  "textRaw": "`node:` imports",
                  "name": "`node:`_imports",
                  "type": "module",
                  "meta": {
                    "added": [
                      "v14.13.1",
                      "v12.20.0"
                    ],
                    "changes": [
                      {
                        "version": [
                          "v16.0.0",
                          "v14.18.0"
                        ],
                        "pr-url": "https://github.com/nodejs/node/pull/37246",
                        "description": "Added `node:` import support to `require(...)`."
                      }
                    ]
                  },
                  "desc": "<p><code>node:</code> URLs are supported as an alternative means to load Node.js builtin\nmodules. This URL scheme allows for builtin modules to be referenced by valid\nabsolute URL strings.</p>\n<pre><code class=\"language-js\">import fs from 'node:fs/promises';\n</code></pre>\n<p><a id=\"import-assertions\"></a></p>",
                  "displayName": "`node:` imports"
                }
              ],
              "displayName": "URLs"
            }
          ],
          "displayName": "`import` Specifiers"
        },
        {
          "textRaw": "Import attributes",
          "name": "import_attributes",
          "type": "misc",
          "meta": {
            "added": [
              "v17.1.0",
              "v16.14.0"
            ],
            "changes": [
              {
                "version": [
                  "v21.0.0",
                  "v20.10.0",
                  "v18.20.0"
                ],
                "pr-url": "https://github.com/nodejs/node/pull/50140",
                "description": "Switch from Import Assertions to Import Attributes."
              }
            ]
          },
          "desc": "<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with\">Import attributes</a> are an inline syntax for module import\nstatements to pass on more information alongside the module specifier.</p>\n<pre><code class=\"language-js\">import fooData from './foo.json' with { type: 'json' };\n\nconst { default: barData } =\n  await import('./bar.json', { with: { type: 'json' } });\n</code></pre>\n<p>Node.js only supports the <code>type</code> attribute, for which it supports the following values:</p>\n<table>\n<thead>\n<tr>\n<th>Attribute <code>type</code></th>\n<th>Needed for</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>'json'</code></td>\n<td><a href=\"#json-modules\">JSON modules</a></td>\n</tr>\n<tr>\n<td><code>'text'</code></td>\n<td><a href=\"#text-modules\">Text modules</a></td>\n</tr>\n</tbody>\n</table>\n<p>The <code>type: 'json'</code> attribute is mandatory when importing JSON modules.\nThe <code>type: 'text'</code> attribute is mandatory when importing text modules.</p>",
          "displayName": "Import attributes"
        },
        {
          "textRaw": "Built-in modules",
          "name": "built-in_modules",
          "type": "misc",
          "desc": "<p><a href=\"modules.html#built-in-modules\">Built-in modules</a> provide named exports of their public API. A\ndefault export is also provided which is the value of the CommonJS exports.\nThe default export can be used for, among other things, modifying the named\nexports. Named exports of built-in modules are updated only by calling\n<a href=\"module.html#modulesyncbuiltinesmexports\"><code>module.syncBuiltinESMExports()</code></a>.</p>\n<pre><code class=\"language-js\">import EventEmitter from 'node:events';\nconst e = new EventEmitter();\n</code></pre>\n<pre><code class=\"language-js\">import { readFile } from 'node:fs';\nreadFile('./foo.txt', (err, source) => {\n  if (err) {\n    console.error(err);\n  } else {\n    console.log(source);\n  }\n});\n</code></pre>\n<pre><code class=\"language-js\">import fs, { readFileSync } from 'node:fs';\nimport { syncBuiltinESMExports } from 'node:module';\nimport { Buffer } from 'node:buffer';\n\nfs.readFileSync = () => Buffer.from('Hello, ESM');\nsyncBuiltinESMExports();\n\nfs.readFileSync === readFileSync;\n</code></pre>\n<blockquote>\n<p>When importing built-in modules, all the named exports (i.e. properties of the module exports object)\nare populated even if they are not individually accessed.\nThis can make initial imports of built-in modules slightly slower compared to loading them with\n<code>require()</code> or <code>process.getBuiltinModule()</code>, where the module exports object is evaluated immediately,\nbut some of its properties may only be initialized when first accessed individually.</p>\n</blockquote>",
          "displayName": "Built-in modules"
        },
        {
          "textRaw": "`import()` expressions",
          "name": "`import()`_expressions",
          "type": "misc",
          "desc": "<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import\">Dynamic <code>import()</code></a> provides an asynchronous way to import modules. It is\nsupported in both CommonJS and ES modules, and can be used to load both CommonJS\nand ES modules.</p>",
          "displayName": "`import()` expressions"
        },
        {
          "textRaw": "Interoperability with CommonJS",
          "name": "interoperability_with_commonjs",
          "type": "misc",
          "modules": [
            {
              "textRaw": "`import` statements",
              "name": "`import`_statements",
              "type": "module",
              "desc": "<p>An <code>import</code> statement can reference an ES module or a CommonJS module.\n<code>import</code> statements are permitted only in ES modules, but dynamic <a href=\"#import-expressions\"><code>import()</code></a>\nexpressions are supported in CommonJS for loading ES modules.</p>\n<p>When importing <a href=\"#commonjs-namespaces\">CommonJS modules</a>, the\n<code>module.exports</code> object is provided as the default export. Named exports may be\navailable, provided by static analysis as a convenience for better ecosystem\ncompatibility.</p>",
              "displayName": "`import` statements"
            },
            {
              "textRaw": "`require`",
              "name": "`require`",
              "type": "module",
              "desc": "<p>The CommonJS module <code>require</code> currently only supports loading synchronous ES\nmodules (that is, ES modules that do not use top-level <code>await</code>).</p>\n<p>See <a href=\"modules.html#loading-ecmascript-modules-using-require\">Loading ECMAScript modules using <code>require()</code></a> for details.</p>",
              "displayName": "`require`"
            },
            {
              "textRaw": "CommonJS Namespaces",
              "name": "commonjs_namespaces",
              "type": "module",
              "meta": {
                "added": [
                  "v14.13.0"
                ],
                "changes": [
                  {
                    "version": "v23.0.0",
                    "pr-url": "https://github.com/nodejs/node/pull/53848",
                    "description": "Added `'module.exports'` export marker to CJS namespaces."
                  }
                ]
              },
              "desc": "<p>CommonJS modules consist of a <code>module.exports</code> object which can be of any type.</p>\n<p>To support this, when importing CommonJS from an ECMAScript module, a namespace\nwrapper for the CommonJS module is constructed, which always provides a\n<code>default</code> export key pointing to the CommonJS <code>module.exports</code> value.</p>\n<p>In addition, a heuristic static analysis is performed against the source text of\nthe CommonJS module to get a best-effort static list of exports to provide on\nthe namespace from values on <code>module.exports</code>. This is necessary since these\nnamespaces must be constructed prior to the evaluation of the CJS module.</p>\n<p>These CommonJS namespace objects also provide the <code>default</code> export as a\n<code>'module.exports'</code> named export, in order to unambiguously indicate that their\nrepresentation in CommonJS uses this value, and not the namespace value. This\nmirrors the semantics of the handling of the <code>'module.exports'</code> export name in\n<a href=\"modules.html#loading-ecmascript-modules-using-require\"><code>require(esm)</code></a> interop support.</p>\n<p>When importing a CommonJS module, it can be reliably imported using the ES\nmodule default import or its corresponding sugar syntax:</p>\n<pre><code class=\"language-js\">import { default as cjs } from 'cjs';\n// Identical to the above\nimport cjsSugar from 'cjs';\n\nconsole.log(cjs);\nconsole.log(cjs === cjsSugar);\n// Prints:\n//   &#x3C;module.exports>\n//   true\n</code></pre>\n<p>This Module Namespace Exotic Object can be directly observed either when using\n<code>import * as m from 'cjs'</code> or a dynamic import:</p>\n<pre><code class=\"language-js\">import * as m from 'cjs';\nconsole.log(m);\nconsole.log(m === await import('cjs'));\n// Prints:\n//   [Module] { default: &#x3C;module.exports>, 'module.exports': &#x3C;module.exports> }\n//   true\n</code></pre>\n<p>For better compatibility with existing usage in the JS ecosystem, Node.js\nin addition attempts to determine the CommonJS named exports of every imported\nCommonJS module to provide them as separate ES module exports using a static\nanalysis process.</p>\n<p>For example, consider a CommonJS module written:</p>\n<pre><code class=\"language-cjs\">// cjs.cjs\nexports.name = 'exported';\n</code></pre>\n<p>The preceding module supports named imports in ES modules:</p>\n<pre><code class=\"language-js\">import { name } from './cjs.cjs';\nconsole.log(name);\n// Prints: 'exported'\n\nimport cjs from './cjs.cjs';\nconsole.log(cjs);\n// Prints: { name: 'exported' }\n\nimport * as m from './cjs.cjs';\nconsole.log(m);\n// Prints:\n//   [Module] {\n//     default: { name: 'exported' },\n//     'module.exports': { name: 'exported' },\n//     name: 'exported'\n//   }\n</code></pre>\n<p>As can be seen from the last example of the Module Namespace Exotic Object being\nlogged, the <code>name</code> export is copied off of the <code>module.exports</code> object and set\ndirectly on the ES module namespace when the module is imported.</p>\n<p>Live binding updates or new exports added to <code>module.exports</code> are not detected\nfor these named exports.</p>\n<p>The detection of named exports is based on common syntax patterns but does not\nalways correctly detect named exports. In these cases, using the default\nimport form described above can be a better option.</p>\n<p>Named exports detection covers many common export patterns, reexport patterns\nand build tool and transpiler outputs. See <a href=\"https://github.com/anonrig/merve/tree/v1.0.0\">merve</a> for the exact\nsemantics implemented.</p>",
              "displayName": "CommonJS Namespaces"
            },
            {
              "textRaw": "Differences between ES modules and CommonJS",
              "name": "differences_between_es_modules_and_commonjs",
              "type": "module",
              "modules": [
                {
                  "textRaw": "No `require`, `exports`, or `module.exports`",
                  "name": "no_`require`,_`exports`,_or_`module.exports`",
                  "type": "module",
                  "desc": "<p>In most cases, the ES module <code>import</code> can be used to load CommonJS modules.</p>\n<p>If needed, a <code>require</code> function can be constructed within an ES module using\n<a href=\"module.html#modulecreaterequirefilename\"><code>module.createRequire()</code></a>.</p>",
                  "displayName": "No `require`, `exports`, or `module.exports`"
                },
                {
                  "textRaw": "No `__filename` or `__dirname`",
                  "name": "no_`__filename`_or_`__dirname`",
                  "type": "module",
                  "desc": "<p>These CommonJS variables are not available in ES modules.</p>\n<p><code>__filename</code> and <code>__dirname</code> use cases can be replicated via\n<a href=\"#importmetafilename\"><code>import.meta.filename</code></a> and <a href=\"#importmetadirname\"><code>import.meta.dirname</code></a>.</p>",
                  "displayName": "No `__filename` or `__dirname`"
                },
                {
                  "textRaw": "No Addon Loading",
                  "name": "no_addon_loading",
                  "type": "module",
                  "desc": "<p><a href=\"addons.html\">Addons</a> are not currently supported with ES module imports.</p>\n<p>They can instead be loaded with <a href=\"module.html#modulecreaterequirefilename\"><code>module.createRequire()</code></a> or\n<a href=\"process.html#processdlopenmodule-filename-flags\"><code>process.dlopen</code></a>.</p>",
                  "displayName": "No Addon Loading"
                },
                {
                  "textRaw": "No `require.main`",
                  "name": "no_`require.main`",
                  "type": "module",
                  "desc": "<p>To replace <code>require.main === module</code>, there is the <a href=\"#importmetamain\"><code>import.meta.main</code></a> API.</p>",
                  "displayName": "No `require.main`"
                },
                {
                  "textRaw": "No `require.resolve`",
                  "name": "no_`require.resolve`",
                  "type": "module",
                  "desc": "<p>Relative resolution can be handled via <code>new URL('./local', import.meta.url)</code>.</p>\n<p>For a complete <code>require.resolve</code> replacement, there is the\n<a href=\"#importmetaresolvespecifier\">import.meta.resolve</a> API.</p>\n<p>Alternatively <code>module.createRequire()</code> can be used.</p>",
                  "displayName": "No `require.resolve`"
                },
                {
                  "textRaw": "No `NODE_PATH`",
                  "name": "no_`node_path`",
                  "type": "module",
                  "desc": "<p><code>NODE_PATH</code> is not part of resolving <code>import</code> specifiers. Please use symlinks\nif this behavior is desired.</p>",
                  "displayName": "No `NODE_PATH`"
                },
                {
                  "textRaw": "No `require.extensions`",
                  "name": "no_`require.extensions`",
                  "type": "module",
                  "desc": "<p><code>require.extensions</code> is not used by <code>import</code>. Module customization hooks can\nprovide a replacement.</p>",
                  "displayName": "No `require.extensions`"
                },
                {
                  "textRaw": "No `require.cache`",
                  "name": "no_`require.cache`",
                  "type": "module",
                  "desc": "<p><code>require.cache</code> is not used by <code>import</code> as the ES module loader has its own\nseparate cache.</p>\n<p><i id=\"esm_experimental_json_modules\"></i></p>",
                  "displayName": "No `require.cache`"
                }
              ],
              "displayName": "Differences between ES modules and CommonJS"
            }
          ],
          "displayName": "Interoperability with CommonJS"
        },
        {
          "textRaw": "JSON modules",
          "name": "json_modules",
          "type": "misc",
          "meta": {
            "changes": [
              {
                "version": [
                  "v23.1.0",
                  "v22.12.0",
                  "v20.18.3",
                  "v18.20.5"
                ],
                "pr-url": "https://github.com/nodejs/node/pull/55333",
                "description": "JSON modules are no longer experimental."
              }
            ]
          },
          "desc": "<p>JSON files can be referenced by <code>import</code>:</p>\n<pre><code class=\"language-js\">import packageConfig from './package.json' with { type: 'json' };\n</code></pre>\n<p>The <code>with { type: 'json' }</code> syntax is mandatory; see <a href=\"#import-attributes\">Import Attributes</a>.</p>\n<p>The imported JSON only exposes a <code>default</code> export. There is no support for named\nexports. A cache entry is created in the CommonJS cache to avoid duplication.\nThe same object is returned in CommonJS if the JSON module has already been\nimported from the same path.</p>",
          "displayName": "JSON modules"
        },
        {
          "textRaw": "Text modules",
          "name": "text_modules",
          "type": "misc",
          "stability": 1,
          "stabilityText": "Early development",
          "desc": "<p>Text modules are available behind the <code>--experimental-import-text</code> flag.</p>\n<p>Text files can be referenced by <code>import</code>:</p>\n<pre><code class=\"language-js\">import message from './message.txt' with { type: 'text' };\n</code></pre>\n<p>The <code>with { type: 'text' }</code> syntax is mandatory; see <a href=\"#import-attributes\">Import Attributes</a>.</p>\n<p>The imported text only exposes a <code>default</code> export whose value is the module\nsource as a string.</p>\n<p><i id=\"esm_experimental_wasm_modules\"></i></p>",
          "displayName": "Text modules"
        },
        {
          "textRaw": "Wasm modules",
          "name": "wasm_modules",
          "type": "misc",
          "meta": {
            "changes": [
              {
                "version": [
                  "v24.5.0",
                  "v22.19.0"
                ],
                "pr-url": "https://github.com/nodejs/node/pull/57038",
                "description": "Wasm modules no longer require the `--experimental-wasm-modules` flag."
              }
            ]
          },
          "desc": "<p>Importing both WebAssembly module instances and WebAssembly source phase\nimports is supported.</p>\n<p>Both of these integrations are in line with the\n<a href=\"https://github.com/webassembly/esm-integration\">ES Module Integration Proposal for WebAssembly</a>.</p>",
          "modules": [
            {
              "textRaw": "Wasm Source Phase Imports",
              "name": "wasm_source_phase_imports",
              "type": "module",
              "meta": {
                "added": [
                  "v24.0.0"
                ],
                "changes": []
              },
              "stability": 1.2,
              "stabilityText": "Release candidate",
              "desc": "<p>The <a href=\"https://github.com/tc39/proposal-source-phase-imports\">Source Phase Imports</a> proposal allows the <code>import source</code> keyword\ncombination to import a <code>WebAssembly.Module</code> object directly, instead of getting\na module instance already instantiated with its dependencies.</p>\n<p>This is useful when needing custom instantiations for Wasm, while still\nresolving and loading it through the ES module integration.</p>\n<p>For example, to create multiple instances of a module, or to pass custom imports\ninto a new instance of <code>library.wasm</code>:</p>\n<pre><code class=\"language-js\">import source libraryModule from './library.wasm';\n\nconst instance1 = await WebAssembly.instantiate(libraryModule, importObject1);\n\nconst instance2 = await WebAssembly.instantiate(libraryModule, importObject2);\n</code></pre>\n<p>In addition to the static source phase, there is also a dynamic variant of the\nsource phase via the <code>import.source</code> dynamic phase import syntax:</p>\n<pre><code class=\"language-js\">const dynamicLibrary = await import.source('./library.wasm');\n\nconst instance = await WebAssembly.instantiate(dynamicLibrary, importObject);\n</code></pre>",
              "displayName": "Wasm Source Phase Imports"
            },
            {
              "textRaw": "JavaScript String Builtins",
              "name": "javascript_string_builtins",
              "type": "module",
              "meta": {
                "added": [
                  "v24.5.0",
                  "v22.19.0"
                ],
                "changes": []
              },
              "stability": 1.2,
              "stabilityText": "Release candidate",
              "desc": "<p>When importing WebAssembly modules, the\n<a href=\"https://github.com/WebAssembly/js-string-builtins\">WebAssembly JS String Builtins Proposal</a> is automatically enabled through the\nESM Integration. This allows WebAssembly modules to directly use efficient\ncompile-time string builtins from the <code>wasm:js-string</code> namespace.</p>\n<p>For example, the following Wasm module exports a string <code>getLength</code> function using\nthe <code>wasm:js-string</code> <code>length</code> builtin:</p>\n<pre><code class=\"language-text\">(module\n  ;; Compile-time import of the string length builtin.\n  (import \"wasm:js-string\" \"length\" (func $string_length (param externref) (result i32)))\n\n  ;; Define getLength, taking a JS value parameter assumed to be a string,\n  ;; calling string length on it and returning the result.\n  (func $getLength (param $str externref) (result i32)\n    local.get $str\n    call $string_length\n  )\n\n  ;; Export the getLength function.\n  (export \"getLength\" (func $get_length))\n)\n</code></pre>\n<pre><code class=\"language-js\">import { getLength } from './string-len.wasm';\ngetLength('foo'); // Returns 3.\n</code></pre>\n<p>Wasm builtins are compile-time imports that are linked during module compilation\nrather than during instantiation. They do not behave like normal module graph\nimports and they cannot be inspected via <code>WebAssembly.Module.imports(mod)</code>\nor virtualized unless recompiling the module using the direct\n<code>WebAssembly.compile</code> API with string builtins disabled.</p>\n<p>String constants may also be imported from the <code>wasm:js/string-constants</code> builtin\nimport URL, allowing static JS string globals to be defined:</p>\n<pre><code class=\"language-text\">(module\n  (import \"wasm:js/string-constants\" \"hello\" (global $hello externref))\n)\n</code></pre>\n<p>Importing a module in the source phase before it has been instantiated will also\nuse the compile-time builtins automatically:</p>\n<pre><code class=\"language-js\">import source mod from './string-len.wasm';\nconst { exports: { getLength } } = await WebAssembly.instantiate(mod, {});\ngetLength('foo'); // Also returns 3.\n</code></pre>",
              "displayName": "JavaScript String Builtins"
            },
            {
              "textRaw": "Wasm Instance Phase Imports",
              "name": "wasm_instance_phase_imports",
              "type": "module",
              "stability": 1.1,
              "stabilityText": "Active development",
              "desc": "<p>Instance imports allow any <code>.wasm</code> files to be imported as normal modules,\nsupporting their module imports in turn.</p>\n<p>For example, an <code>index.js</code> containing:</p>\n<pre><code class=\"language-js\">import * as M from './library.wasm';\nconsole.log(M);\n</code></pre>\n<p>executed under:</p>\n<pre><code class=\"language-bash\">node index.mjs\n</code></pre>\n<p>would provide the exports interface for the instantiation of <code>library.wasm</code>.</p>",
              "displayName": "Wasm Instance Phase Imports"
            },
            {
              "textRaw": "Reserved Wasm Namespaces",
              "name": "reserved_wasm_namespaces",
              "type": "module",
              "meta": {
                "added": [
                  "v24.5.0",
                  "v22.19.0"
                ],
                "changes": []
              },
              "desc": "<p>When importing WebAssembly module instances, they cannot use import module\nnames or import/export names that start with reserved prefixes:</p>\n<ul>\n<li><code>wasm-js:</code> - reserved in all module import names, module names and export\nnames.</li>\n<li><code>wasm:</code> - reserved in module import names and export names (imported module\nnames are allowed in order to support future builtin polyfills).</li>\n</ul>\n<p>Importing a module using the above reserved names will throw a\n<code>WebAssembly.LinkError</code>.</p>\n<p><i id=\"esm_experimental_top_level_await\"></i></p>",
              "displayName": "Reserved Wasm Namespaces"
            }
          ],
          "displayName": "Wasm modules"
        },
        {
          "textRaw": "Top-level `await`",
          "name": "top-level_`await`",
          "type": "misc",
          "meta": {
            "added": [
              "v14.8.0"
            ],
            "changes": []
          },
          "desc": "<p>The <code>await</code> keyword may be used in the top level body of an ECMAScript module.</p>\n<p>Assuming an <code>a.mjs</code> with</p>\n<pre><code class=\"language-js\">export const five = await Promise.resolve(5);\n</code></pre>\n<p>And a <code>b.mjs</code> with</p>\n<pre><code class=\"language-js\">import { five } from './a.mjs';\n\nconsole.log(five); // Logs `5`\n</code></pre>\n<pre><code class=\"language-bash\">node b.mjs # works\n</code></pre>\n<p>If a top level <code>await</code> expression never resolves, the <code>node</code> process will exit\nwith a <code>13</code> <a href=\"process.html#exit-codes\">status code</a>.</p>\n<pre><code class=\"language-js\">import { spawn } from 'node:child_process';\nimport { execPath } from 'node:process';\n\nspawn(execPath, [\n  '--input-type=module',\n  '--eval',\n  // Never-resolving Promise:\n  'await new Promise(() => {})',\n]).once('exit', (code) => {\n  console.log(code); // Logs `13`\n});\n</code></pre>\n<p><i id=\"esm_experimental_loaders\"></i></p>",
          "displayName": "Top-level `await`"
        },
        {
          "textRaw": "Loaders",
          "name": "loaders",
          "type": "misc",
          "desc": "<p>The former Loaders documentation is now at\n<a href=\"module.html#customization-hooks\">Modules: Customization hooks</a>.</p>",
          "displayName": "Loaders"
        },
        {
          "textRaw": "Resolution and loading algorithm",
          "name": "resolution_and_loading_algorithm",
          "type": "misc",
          "modules": [
            {
              "textRaw": "Features",
              "name": "features",
              "type": "module",
              "desc": "<p>The default resolver has the following properties:</p>\n<ul>\n<li>FileURL-based resolution as is used by ES modules</li>\n<li>Relative and absolute URL resolution</li>\n<li>No default extensions</li>\n<li>No folder mains</li>\n<li>Bare specifier package resolution lookup through node_modules</li>\n<li>Does not fail on unknown extensions or protocols</li>\n<li>Can optionally provide a hint of the format to the loading phase</li>\n</ul>\n<p>The default loader has the following properties</p>\n<ul>\n<li>Support for builtin module loading via <code>node:</code> URLs</li>\n<li>Support for \"inline\" module loading via <code>data:</code> URLs</li>\n<li>Support for <code>file:</code> module loading</li>\n<li>Fails on any other URL protocol</li>\n<li>Fails on unknown extensions for <code>file:</code> loading\n(supports only <code>.cjs</code>, <code>.js</code>, and <code>.mjs</code>)</li>\n</ul>\n<p>When the <a href=\"cli.html#--experimental-package-mappath\"><code>--experimental-package-map</code></a> flag is enabled, bare specifier\nresolution first consults the package map configuration. If the importing\nmodule is within a mapped package and the specifier matches a declared\ndependency, the package map resolution takes precedence. See <a href=\"packages.html#package-maps\">Package maps</a>\nfor details.</p>",
              "displayName": "Features"
            },
            {
              "textRaw": "Resolution algorithm",
              "name": "resolution_algorithm",
              "type": "module",
              "desc": "<p>The algorithm to load an ES module specifier is given through the\n<strong>ESM_RESOLVE</strong> method below. It returns the resolved URL for a\nmodule specifier relative to a parentURL.</p>\n<p>The resolution algorithm determines the full resolved URL for a module\nload, along with its suggested module format. The resolution algorithm\ndoes not determine whether the resolved URL protocol can be loaded,\nor whether the file extensions are permitted, instead these validations\nare applied by Node.js during the load phase\n(for example, if it was asked to load a URL that has a protocol that is\nnot <code>file:</code>, <code>data:</code> or <code>node:</code>.</p>\n<p>The algorithm also tries to determine the format of the file based\non the extension (see <code>ESM_FILE_FORMAT</code> algorithm below). If it does\nnot recognize the file extension (eg if it is not <code>.mjs</code>, <code>.cjs</code>, or\n<code>.json</code>), then a format of <code>undefined</code> is returned,\nwhich will throw during the load phase.</p>\n<p>The algorithm to determine the module format of a resolved URL is\nprovided by <strong>ESM_FILE_FORMAT</strong>, which returns the unique module\nformat for any file. The <em>\"module\"</em> format is returned for an ECMAScript\nModule, while the <em>\"commonjs\"</em> format is used to indicate loading through the\nlegacy CommonJS loader. Additional formats such as <em>\"addon\"</em> can be extended in\nfuture updates.</p>\n<p>In the following algorithms, all subroutine errors are propagated as errors\nof these top-level routines unless stated otherwise.</p>\n<p><em>defaultConditions</em> is the conditional environment name array,\n<code>[\"node\", \"import\"]</code>.</p>\n<p>The resolver can throw the following errors:</p>\n<ul>\n<li><em>Invalid Module Specifier</em>: Module specifier is an invalid URL, package name\nor package subpath specifier.</li>\n<li><em>Invalid Package Configuration</em>: package.json configuration is invalid or\ncontains an invalid configuration.</li>\n<li><em>Invalid Package Target</em>: Package exports or imports define a target module\nfor the package that is an invalid type or string target.</li>\n<li><em>Package Path Not Exported</em>: Package exports do not define or permit a target\nsubpath in the package for the given module.</li>\n<li><em>Package Import Not Defined</em>: Package imports do not define the specifier.</li>\n<li><em>Module Not Found</em>: The package or module requested does not exist.</li>\n<li><em>Unsupported Directory Import</em>: The resolved path corresponds to a directory,\nwhich is not a supported target for module imports.</li>\n</ul>",
              "displayName": "Resolution algorithm"
            },
            {
              "textRaw": "Resolution Algorithm Specification",
              "name": "resolution_algorithm_specification",
              "type": "module",
              "desc": "<p><strong>ESM_RESOLVE</strong>(<em>specifier</em>, <em>parentURL</em>)</p>\n<blockquote>\n<ol>\n<li>Let <em>resolved</em> be <strong>undefined</strong>.</li>\n<li>If <em>specifier</em> is a valid URL, then\n<ol>\n<li>Set <em>resolved</em> to the result of parsing and reserializing\n<em>specifier</em> as a URL.</li>\n</ol>\n</li>\n<li>Otherwise, if <em>specifier</em> starts with <em>\"/\"</em>, <em>\"./\"</em>, or <em>\"../\"</em>, then\n<ol>\n<li>Set <em>resolved</em> to the URL resolution of <em>specifier</em> relative to\n<em>parentURL</em>.</li>\n</ol>\n</li>\n<li>Otherwise, if <em>specifier</em> starts with <em>\"#\"</em>, then\n<ol>\n<li>Set <em>resolved</em> to the result of\n<strong>PACKAGE_IMPORTS_RESOLVE</strong>(<em>specifier</em>,\n<em>parentURL</em>, <em>defaultConditions</em>).</li>\n</ol>\n</li>\n<li>Otherwise,\n<ol>\n<li>Note: <em>specifier</em> is now a bare specifier.</li>\n<li>Set <em>resolved</em> the result of\n<strong>PACKAGE_RESOLVE</strong>(<em>specifier</em>, <em>parentURL</em>).</li>\n</ol>\n</li>\n<li>Let <em>format</em> be <strong>undefined</strong>.</li>\n<li>If <em>resolved</em> is a <em>\"file:\"</em> URL, then\n<ol>\n<li>If <em>resolved</em> contains any percent encodings of <em>\"/\"</em> or <em>\"\\\"</em> (<em>\"%2F\"</em>\nand <em>\"%5C\"</em> respectively), then\n<ol>\n<li>Throw an <em>Invalid Module Specifier</em> error.</li>\n</ol>\n</li>\n<li>If the file at <em>resolved</em> is a directory, then\n<ol>\n<li>Throw an <em>Unsupported Directory Import</em> error.</li>\n</ol>\n</li>\n<li>If the file at <em>resolved</em> does not exist, then\n<ol>\n<li>Throw a <em>Module Not Found</em> error.</li>\n</ol>\n</li>\n<li>Set <em>resolved</em> to the real path of <em>resolved</em>, maintaining the\nsame URL querystring and fragment components.</li>\n<li>Set <em>format</em> to the result of <strong>ESM_FILE_FORMAT</strong>(<em>resolved</em>).</li>\n</ol>\n</li>\n<li>Otherwise,\n<ol>\n<li>Set <em>format</em> the module format of the content type associated with the\nURL <em>resolved</em>.</li>\n</ol>\n</li>\n<li>Return <em>format</em> and <em>resolved</em> to the loading phase</li>\n</ol>\n</blockquote>\n<p><strong>PACKAGE_RESOLVE</strong>(<em>packageSpecifier</em>, <em>parentURL</em>)</p>\n<blockquote>\n<ol>\n<li>Let <em>packageName</em> be <strong>undefined</strong>.</li>\n<li>If <em>packageSpecifier</em> is an empty string, then\n<ol>\n<li>Throw an <em>Invalid Module Specifier</em> error.</li>\n</ol>\n</li>\n<li>If <em>packageSpecifier</em> is a Node.js builtin module name, then\n<ol>\n<li>Return the string <em>\"node:\"</em> concatenated with <em>packageSpecifier</em>.</li>\n</ol>\n</li>\n<li>If <em>packageSpecifier</em> does not start with <em>\"@\"</em>, then\n<ol>\n<li>Set <em>packageName</em> to the substring of <em>packageSpecifier</em> until the first\n<em>\"/\"</em> separator or the end of the string.</li>\n</ol>\n</li>\n<li>Otherwise,\n<ol>\n<li>If <em>packageSpecifier</em> does not contain a <em>\"/\"</em> separator, then\n<ol>\n<li>Throw an <em>Invalid Module Specifier</em> error.</li>\n</ol>\n</li>\n<li>Set <em>packageName</em> to the substring of <em>packageSpecifier</em>\nuntil the second <em>\"/\"</em> separator or the end of the string.</li>\n</ol>\n</li>\n<li>If <em>packageName</em> starts with <em>\".\"</em> or contains <em>\"\\\"</em> or <em>\"%\"</em>, then\n<ol>\n<li>Throw an <em>Invalid Module Specifier</em> error.</li>\n</ol>\n</li>\n<li>Let <em>packageSubpath</em> be <em>\".\"</em> concatenated with the substring of\n<em>packageSpecifier</em> from the position at the length of <em>packageName</em>.</li>\n<li>Let <em>selfUrl</em> be the result of\n<strong>PACKAGE_SELF_RESOLVE</strong>(<em>packageName</em>, <em>packageSubpath</em>, <em>parentURL</em>).</li>\n<li>If <em>selfUrl</em> is not <strong>undefined</strong>, return <em>selfUrl</em>.</li>\n<li>While <em>parentURL</em> is not the file system root,\n<ol>\n<li>Let <em>packageURL</em> be the URL resolution of <em>\"node_modules/\"</em>\nconcatenated with <em>packageName</em>, relative to <em>parentURL</em>.</li>\n<li>Set <em>parentURL</em> to the parent folder URL of <em>parentURL</em>.</li>\n<li>If the folder at <em>packageURL</em> does not exist, then\n<ol>\n<li>Continue the next loop iteration.</li>\n</ol>\n</li>\n<li>Let <em>pjson</em> be the result of <strong>READ_PACKAGE_JSON</strong>(<em>packageURL</em>).</li>\n<li>If <em>pjson</em> is not <strong>null</strong> and <em>pjson</em>.<em>exports</em> is not <strong>null</strong> or\n<strong>undefined</strong>, then\n<ol>\n<li>Return the result of <strong>PACKAGE_EXPORTS_RESOLVE</strong>(<em>packageURL</em>,\n<em>packageSubpath</em>, <em>pjson.exports</em>, <em>defaultConditions</em>).</li>\n</ol>\n</li>\n<li>Otherwise, if <em>packageSubpath</em> is equal to <em>\".\"</em>, then\n<ol>\n<li>If <em>pjson.main</em> is a string, then\n<ol>\n<li>Return the URL resolution of <em>main</em> in <em>packageURL</em>.</li>\n</ol>\n</li>\n</ol>\n</li>\n<li>Otherwise,\n<ol>\n<li>Return the URL resolution of <em>packageSubpath</em> in <em>packageURL</em>.</li>\n</ol>\n</li>\n</ol>\n</li>\n<li>Throw a <em>Module Not Found</em> error.</li>\n</ol>\n</blockquote>\n<p><strong>PACKAGE_SELF_RESOLVE</strong>(<em>packageName</em>, <em>packageSubpath</em>, <em>parentURL</em>)</p>\n<blockquote>\n<ol>\n<li>Let <em>packageURL</em> be the result of <strong>LOOKUP_PACKAGE_SCOPE</strong>(<em>parentURL</em>).</li>\n<li>If <em>packageURL</em> is <strong>null</strong>, then\n<ol>\n<li>Return <strong>undefined</strong>.</li>\n</ol>\n</li>\n<li>Let <em>pjson</em> be the result of <strong>READ_PACKAGE_JSON</strong>(<em>packageURL</em>).</li>\n<li>If <em>pjson</em> is <strong>null</strong> or if <em>pjson</em>.<em>exports</em> is <strong>null</strong> or\n<strong>undefined</strong>, then\n<ol>\n<li>Return <strong>undefined</strong>.</li>\n</ol>\n</li>\n<li>If <em>pjson.name</em> is equal to <em>packageName</em>, then\n<ol>\n<li>Return the result of <strong>PACKAGE_EXPORTS_RESOLVE</strong>(<em>packageURL</em>,\n<em>packageSubpath</em>, <em>pjson.exports</em>, <em>defaultConditions</em>).</li>\n</ol>\n</li>\n<li>Otherwise, return <strong>undefined</strong>.</li>\n</ol>\n</blockquote>\n<p><strong>PACKAGE_EXPORTS_RESOLVE</strong>(<em>packageURL</em>, <em>subpath</em>, <em>exports</em>, <em>conditions</em>)</p>\n<p>Note: This function is directly invoked by the CommonJS resolution algorithm.</p>\n<blockquote>\n<ol>\n<li>If <em>exports</em> is an Object with both a key starting with <em>\".\"</em> and a key not\nstarting with <em>\".\"</em>, throw an <em>Invalid Package Configuration</em> error.</li>\n<li>If <em>subpath</em> is equal to <em>\".\"</em>, then\n<ol>\n<li>Let <em>mainExport</em> be <strong>undefined</strong>.</li>\n<li>If <em>exports</em> is a String or Array, or an Object containing no keys\nstarting with <em>\".\"</em>, then\n<ol>\n<li>Set <em>mainExport</em> to <em>exports</em>.</li>\n</ol>\n</li>\n<li>Otherwise if <em>exports</em> is an Object containing a <em>\".\"</em> property, then\n<ol>\n<li>Set <em>mainExport</em> to <em>exports</em>[<em>\".\"</em>].</li>\n</ol>\n</li>\n<li>If <em>mainExport</em> is not <strong>undefined</strong>, then\n<ol>\n<li>Let <em>resolved</em> be the result of <strong>PACKAGE_TARGET_RESOLVE</strong>(\n<em>packageURL</em>, <em>mainExport</em>, <strong>null</strong>, <strong>false</strong>, <em>conditions</em>).</li>\n<li>If <em>resolved</em> is not <strong>null</strong> or <strong>undefined</strong>, return <em>resolved</em>.</li>\n</ol>\n</li>\n</ol>\n</li>\n<li>Otherwise, if <em>exports</em> is an Object and all keys of <em>exports</em> start with\n<em>\".\"</em>, then\n<ol>\n<li>Assert: <em>subpath</em> begins with <em>\"./\"</em>.</li>\n<li>Let <em>resolved</em> be the result of <strong>PACKAGE_IMPORTS_EXPORTS_RESOLVE</strong>(\n<em>subpath</em>, <em>exports</em>, <em>packageURL</em>, <strong>false</strong>, <em>conditions</em>).</li>\n<li>If <em>resolved</em> is not <strong>null</strong> or <strong>undefined</strong>, return <em>resolved</em>.</li>\n</ol>\n</li>\n<li>Throw a <em>Package Path Not Exported</em> error.</li>\n</ol>\n</blockquote>\n<p><strong>PACKAGE_IMPORTS_RESOLVE</strong>(<em>specifier</em>, <em>parentURL</em>, <em>conditions</em>)</p>\n<p>Note: This function is directly invoked by the CommonJS resolution algorithm.</p>\n<blockquote>\n<ol>\n<li>Assert: <em>specifier</em> begins with <em>\"#\"</em>.</li>\n<li>If <em>specifier</em> is exactly equal to <em>\"#\"</em>, then\n<ol>\n<li>Throw an <em>Invalid Module Specifier</em> error.</li>\n</ol>\n</li>\n<li>Let <em>packageURL</em> be the result of <strong>LOOKUP_PACKAGE_SCOPE</strong>(<em>parentURL</em>).</li>\n<li>If <em>packageURL</em> is not <strong>null</strong>, then\n<ol>\n<li>Let <em>pjson</em> be the result of <strong>READ_PACKAGE_JSON</strong>(<em>packageURL</em>).</li>\n<li>If <em>pjson.imports</em> is a non-null Object, then\n<ol>\n<li>Let <em>resolved</em> be the result of\n<strong>PACKAGE_IMPORTS_EXPORTS_RESOLVE</strong>(\n<em>specifier</em>, <em>pjson.imports</em>, <em>packageURL</em>, <strong>true</strong>, <em>conditions</em>).</li>\n<li>If <em>resolved</em> is not <strong>null</strong> or <strong>undefined</strong>, return <em>resolved</em>.</li>\n</ol>\n</li>\n</ol>\n</li>\n<li>Throw a <em>Package Import Not Defined</em> error.</li>\n</ol>\n</blockquote>\n<p><strong>PACKAGE_IMPORTS_EXPORTS_RESOLVE</strong>(<em>matchKey</em>, <em>matchObj</em>, <em>packageURL</em>,\n<em>isImports</em>, <em>conditions</em>)</p>\n<blockquote>\n<ol>\n<li>If <em>matchKey</em> ends in <em>\"/\"</em>, then\n<ol>\n<li>Throw an <em>Invalid Module Specifier</em> error.</li>\n</ol>\n</li>\n<li>If <em>matchKey</em> is a key of <em>matchObj</em> and does not contain <em>\"*\"</em>, then\n<ol>\n<li>Let <em>target</em> be the value of <em>matchObj</em>[<em>matchKey</em>].</li>\n<li>Return the result of <strong>PACKAGE_TARGET_RESOLVE</strong>(<em>packageURL</em>,\n<em>target</em>, <strong>null</strong>, <em>isImports</em>, <em>conditions</em>).</li>\n</ol>\n</li>\n<li>Let <em>expansionKeys</em> be the list of keys of <em>matchObj</em> containing only a\nsingle <em>\"*\"</em>, sorted by the sorting function <strong>PATTERN_KEY_COMPARE</strong>\nwhich orders in descending order of specificity.</li>\n<li>For each key <em>expansionKey</em> in <em>expansionKeys</em>, do\n<ol>\n<li>Let <em>patternBase</em> be the substring of <em>expansionKey</em> up to but excluding\nthe first <em>\"*\"</em> character.</li>\n<li>If <em>matchKey</em> starts with but is not equal to <em>patternBase</em>, then\n<ol>\n<li>Let <em>patternTrailer</em> be the substring of <em>expansionKey</em> from the\nindex after the first <em>\"*\"</em> character.</li>\n<li>If <em>patternTrailer</em> has zero length, or if <em>matchKey</em> ends with\n<em>patternTrailer</em> and the length of <em>matchKey</em> is greater than or\nequal to the length of <em>expansionKey</em>, then\n<ol>\n<li>Let <em>target</em> be the value of <em>matchObj</em>[<em>expansionKey</em>].</li>\n<li>Let <em>patternMatch</em> be the substring of <em>matchKey</em> starting at the\nindex of the length of <em>patternBase</em> up to the length of\n<em>matchKey</em> minus the length of <em>patternTrailer</em>.</li>\n<li>Return the result of <strong>PACKAGE_TARGET_RESOLVE</strong>(<em>packageURL</em>,\n<em>target</em>, <em>patternMatch</em>, <em>isImports</em>, <em>conditions</em>).</li>\n</ol>\n</li>\n</ol>\n</li>\n</ol>\n</li>\n<li>Return <strong>null</strong>.</li>\n</ol>\n</blockquote>\n<p><strong>PATTERN_KEY_COMPARE</strong>(<em>keyA</em>, <em>keyB</em>)</p>\n<blockquote>\n<ol>\n<li>Assert: <em>keyA</em> contains only a single <em>\"*\"</em>.</li>\n<li>Assert: <em>keyB</em> contains only a single <em>\"*\"</em>.</li>\n<li>Let <em>baseLengthA</em> be the index of <em>\"*\"</em> in <em>keyA</em>.</li>\n<li>Let <em>baseLengthB</em> be the index of <em>\"*\"</em> in <em>keyB</em>.</li>\n<li>If <em>baseLengthA</em> is greater than <em>baseLengthB</em>, return -1.</li>\n<li>If <em>baseLengthB</em> is greater than <em>baseLengthA</em>, return 1.</li>\n<li>If the length of <em>keyA</em> is greater than the length of <em>keyB</em>, return -1.</li>\n<li>If the length of <em>keyB</em> is greater than the length of <em>keyA</em>, return 1.</li>\n<li>Return 0.</li>\n</ol>\n</blockquote>\n<p><strong>PACKAGE_TARGET_RESOLVE</strong>(<em>packageURL</em>, <em>target</em>, <em>patternMatch</em>,\n<em>isImports</em>, <em>conditions</em>)</p>\n<blockquote>\n<ol>\n<li>If <em>target</em> is a String, then\n<ol>\n<li>If <em>target</em> does not start with <em>\"./\"</em>, then\n<ol>\n<li>If <em>isImports</em> is <strong>false</strong>, or if <em>target</em> starts with <em>\"../\"</em> or\n<em>\"/\"</em>, or if <em>target</em> is a valid URL, then\n<ol>\n<li>Throw an <em>Invalid Package Target</em> error.</li>\n</ol>\n</li>\n<li>If <em>patternMatch</em> is a String, then\n<ol>\n<li>Return <strong>PACKAGE_RESOLVE</strong>(<em>target</em> with every instance of <em>\"*\"</em>\nreplaced by <em>patternMatch</em>, <em>packageURL</em> + <em>\"/\"</em>).</li>\n</ol>\n</li>\n<li>Return <strong>PACKAGE_RESOLVE</strong>(<em>target</em>, <em>packageURL</em> + <em>\"/\"</em>).</li>\n</ol>\n</li>\n<li>If <em>target</em> split on <em>\"/\"</em> or <em>\"\\\"</em> contains any <em>\"\"</em>, <em>\".\"</em>, <em>\"..\"</em>,\nor <em>\"node_modules\"</em> segments after the first <em>\".\"</em> segment, case\ninsensitive and including percent encoded variants, throw an <em>Invalid\nPackage Target</em> error.</li>\n<li>Let <em>resolvedTarget</em> be the URL resolution of the concatenation of\n<em>packageURL</em> and <em>target</em>.</li>\n<li>Assert: <em>packageURL</em> is contained in <em>resolvedTarget</em>.</li>\n<li>If <em>patternMatch</em> is <strong>null</strong>, then\n<ol>\n<li>Return <em>resolvedTarget</em>.</li>\n</ol>\n</li>\n<li>If <em>patternMatch</em> split on <em>\"/\"</em> or <em>\"\\\"</em> contains any <em>\"\"</em>, <em>\".\"</em>,\n<em>\"..\"</em>, or <em>\"node_modules\"</em> segments, case insensitive and including\npercent encoded variants, throw an <em>Invalid Module Specifier</em> error.</li>\n<li>Return the URL resolution of <em>resolvedTarget</em> with every instance of\n<em>\"*\"</em> replaced with <em>patternMatch</em>.</li>\n</ol>\n</li>\n<li>Otherwise, if <em>target</em> is a non-null Object, then\n<ol>\n<li>If <em>target</em> contains any index property keys, as defined in ECMA-262\n<a href=\"https://tc39.es/ecma262/#integer-index\">6.1.7 Array Index</a>, throw an <em>Invalid Package Configuration</em> error.</li>\n<li>For each property <em>p</em> of <em>target</em>, in object insertion order as,\n<ol>\n<li>If <em>p</em> equals <em>\"default\"</em> or <em>conditions</em> contains an entry for <em>p</em>,\nthen\n<ol>\n<li>Let <em>targetValue</em> be the value of the <em>p</em> property in <em>target</em>.</li>\n<li>Let <em>resolved</em> be the result of <strong>PACKAGE_TARGET_RESOLVE</strong>(\n<em>packageURL</em>, <em>targetValue</em>, <em>patternMatch</em>, <em>isImports</em>,\n<em>conditions</em>).</li>\n<li>If <em>resolved</em> is equal to <strong>undefined</strong>, continue the loop.</li>\n<li>Return <em>resolved</em>.</li>\n</ol>\n</li>\n</ol>\n</li>\n<li>Return <strong>undefined</strong>.</li>\n</ol>\n</li>\n<li>Otherwise, if <em>target</em> is an Array, then\n<ol>\n<li>If _target.length is zero, return <strong>null</strong>.</li>\n<li>For each item <em>targetValue</em> in <em>target</em>, do\n<ol>\n<li>Let <em>resolved</em> be the result of <strong>PACKAGE_TARGET_RESOLVE</strong>(\n<em>packageURL</em>, <em>targetValue</em>, <em>patternMatch</em>, <em>isImports</em>,\n<em>conditions</em>), continuing the loop on any <em>Invalid Package Target</em>\nerror.</li>\n<li>If <em>resolved</em> is <strong>undefined</strong>, continue the loop.</li>\n<li>Return <em>resolved</em>.</li>\n</ol>\n</li>\n<li>Return or throw the last fallback resolution <strong>null</strong> return or error.</li>\n</ol>\n</li>\n<li>Otherwise, if <em>target</em> is <em>null</em>, return <strong>null</strong>.</li>\n<li>Otherwise throw an <em>Invalid Package Target</em> error.</li>\n</ol>\n</blockquote>\n<p><strong>ESM_FILE_FORMAT</strong>(<em>url</em>)</p>\n<blockquote>\n<ol>\n<li>Assert: <em>url</em> corresponds to an existing file.</li>\n<li>If <em>url</em> ends in <em>\".mjs\"</em>, then\n<ol>\n<li>Return <em>\"module\"</em>.</li>\n</ol>\n</li>\n<li>If <em>url</em> ends in <em>\".cjs\"</em>, then\n<ol>\n<li>Return <em>\"commonjs\"</em>.</li>\n</ol>\n</li>\n<li>If <em>url</em> ends in <em>\".json\"</em>, then\n<ol>\n<li>Return <em>\"json\"</em>.</li>\n</ol>\n</li>\n<li>If <em>url</em> ends in\n<em>\".wasm\"</em>, then\n<ol>\n<li>Return <em>\"wasm\"</em>.</li>\n</ol>\n</li>\n<li>If <code>--experimental-addon-modules</code> is enabled and <em>url</em> ends in\n<em>\".node\"</em>, then\n<ol>\n<li>Return <em>\"addon\"</em>.</li>\n</ol>\n</li>\n<li>Let <em>packageURL</em> be the result of <strong>LOOKUP_PACKAGE_SCOPE</strong>(<em>url</em>).</li>\n<li>Let <em>pjson</em> be the result of <strong>READ_PACKAGE_JSON</strong>(<em>packageURL</em>).</li>\n<li>Let <em>packageType</em> be <strong>null</strong>.</li>\n<li>If <em>pjson?.type</em> is <em>\"module\"</em> or <em>\"commonjs\"</em>, then\n<ol>\n<li>Set <em>packageType</em> to <em>pjson.type</em>.</li>\n</ol>\n</li>\n<li>If <em>url</em> ends in <em>\".js\"</em>, then\n<ol>\n<li>If <em>packageType</em> is not <strong>null</strong>, then\n<ol>\n<li>Return <em>packageType</em>.</li>\n</ol>\n</li>\n<li>If the result of <strong>DETECT_MODULE_SYNTAX</strong>(<em>source</em>) is true, then\n<ol>\n<li>Return <em>\"module\"</em>.</li>\n</ol>\n</li>\n<li>Return <em>\"commonjs\"</em>.</li>\n</ol>\n</li>\n<li>If <em>url</em> does not have any extension, then\n<ol>\n<li>If <em>packageType</em> is <em>\"module\"</em> and the file at <em>url</em> contains the\n\"application/wasm\" content type header for a WebAssembly module, then\n<ol>\n<li>Return <em>\"wasm\"</em>.</li>\n</ol>\n</li>\n<li>If <em>packageType</em> is not <strong>null</strong>, then\n<ol>\n<li>Return <em>packageType</em>.</li>\n</ol>\n</li>\n<li>If the result of <strong>DETECT_MODULE_SYNTAX</strong>(<em>source</em>) is true, then\n<ol>\n<li>Return <em>\"module\"</em>.</li>\n</ol>\n</li>\n<li>Return <em>\"commonjs\"</em>.</li>\n</ol>\n</li>\n<li>Return <strong>undefined</strong> (will throw during load phase).</li>\n</ol>\n</blockquote>\n<p><strong>LOOKUP_PACKAGE_SCOPE</strong>(<em>url</em>)</p>\n<blockquote>\n<ol>\n<li>Let <em>scopeURL</em> be <em>url</em>.</li>\n<li>While <em>scopeURL</em> is not the file system root,\n<ol>\n<li>Set <em>scopeURL</em> to the parent URL of <em>scopeURL</em>.</li>\n<li>If <em>scopeURL</em> ends in a <em>\"node_modules\"</em> path segment, return <strong>null</strong>.</li>\n<li>Let <em>pjsonURL</em> be the resolution of <em>\"package.json\"</em> within\n<em>scopeURL</em>.</li>\n<li>if the file at <em>pjsonURL</em> exists, then\n<ol>\n<li>Return <em>scopeURL</em>.</li>\n</ol>\n</li>\n</ol>\n</li>\n<li>Return <strong>null</strong>.</li>\n</ol>\n</blockquote>\n<p><strong>READ_PACKAGE_JSON</strong>(<em>packageURL</em>)</p>\n<blockquote>\n<ol>\n<li>Let <em>pjsonURL</em> be the resolution of <em>\"package.json\"</em> within <em>packageURL</em>.</li>\n<li>If the file at <em>pjsonURL</em> does not exist, then\n<ol>\n<li>Return <strong>null</strong>.</li>\n</ol>\n</li>\n<li>If the file at <em>packageURL</em> does not parse as valid JSON, then\n<ol>\n<li>Throw an <em>Invalid Package Configuration</em> error.</li>\n</ol>\n</li>\n<li>Return the parsed JSON source of the file at <em>pjsonURL</em>.</li>\n</ol>\n</blockquote>\n<p><strong>DETECT_MODULE_SYNTAX</strong>(<em>source</em>)</p>\n<blockquote>\n<ol>\n<li>Parse <em>source</em> as an ECMAScript module.</li>\n<li>If the parse is successful, then\n<ol>\n<li>If <em>source</em> contains top-level <code>await</code>, static <code>import</code> or <code>export</code>\nstatements, or <code>import.meta</code>, return <strong>true</strong>.</li>\n<li>If <em>source</em> contains a top-level lexical declaration (<code>const</code>, <code>let</code>,\nor <code>class</code>) of any of the CommonJS wrapper variables (<code>require</code>,\n<code>exports</code>, <code>module</code>, <code>__filename</code>, or <code>__dirname</code>) then return <strong>true</strong>.</li>\n</ol>\n</li>\n<li>Return <strong>false</strong>.</li>\n</ol>\n</blockquote>",
              "displayName": "Resolution Algorithm Specification"
            },
            {
              "textRaw": "Customizing ESM specifier resolution algorithm",
              "name": "customizing_esm_specifier_resolution_algorithm",
              "type": "module",
              "desc": "<p><a href=\"module.html#customization-hooks\">Module customization hooks</a> provide a mechanism for customizing the ESM\nspecifier resolution algorithm. An example that provides CommonJS-style\nresolution for ESM specifiers is <a href=\"https://github.com/nodejs/loaders-test/tree/main/commonjs-extension-resolution-loader\">commonjs-extension-resolution-loader</a>.</p>",
              "displayName": "Customizing ESM specifier resolution algorithm"
            }
          ],
          "displayName": "Resolution and loading algorithm"
        }
      ],
      "properties": [
        {
          "textRaw": "Type: {Object}",
          "name": "meta",
          "type": "Object",
          "desc": "<p>The <code>import.meta</code> meta property is an <code>Object</code> that contains the following\nproperties. It is only supported in ES modules.</p>",
          "properties": [
            {
              "textRaw": "Type: {string} The directory name of the current module.",
              "name": "dirname",
              "type": "string",
              "meta": {
                "added": [
                  "v21.2.0",
                  "v20.11.0"
                ],
                "changes": [
                  {
                    "version": [
                      "v24.0.0",
                      "v22.16.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/58011",
                    "description": "This property is no longer experimental."
                  }
                ]
              },
              "desc": "<p>This is the same as the <a href=\"path.html#pathdirnamepath\"><code>path.dirname()</code></a> of the <a href=\"#importmetafilename\"><code>import.meta.filename</code></a>.</p>\n<blockquote>\n<p><strong>Caveat</strong>: only present on <code>file:</code> modules.</p>\n</blockquote>",
              "shortDesc": "The directory name of the current module."
            },
            {
              "textRaw": "Type: {string} The full absolute path and filename of the current module, with symlinks resolved.",
              "name": "filename",
              "type": "string",
              "meta": {
                "added": [
                  "v21.2.0",
                  "v20.11.0"
                ],
                "changes": [
                  {
                    "version": [
                      "v24.0.0",
                      "v22.16.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/58011",
                    "description": "This property is no longer experimental."
                  }
                ]
              },
              "desc": "<p>This is the same as the <a href=\"url.html#urlfileurltopathurl-options\"><code>url.fileURLToPath()</code></a> of the <a href=\"#importmetaurl\"><code>import.meta.url</code></a>.</p>\n<blockquote>\n<p><strong>Caveat</strong> only local modules support this property. Modules not using the\n<code>file:</code> protocol will not provide it.</p>\n</blockquote>",
              "shortDesc": "The full absolute path and filename of the current module, with symlinks resolved."
            },
            {
              "textRaw": "Type: {string} The absolute `file:` URL of the module.",
              "name": "url",
              "type": "string",
              "desc": "<p>This is defined exactly the same as it is in browsers providing the URL of the\ncurrent module file.</p>\n<p>This enables useful patterns such as relative file loading:</p>\n<pre><code class=\"language-js\">import { readFileSync } from 'node:fs';\nconst buffer = readFileSync(new URL('./data.proto', import.meta.url));\n</code></pre>",
              "shortDesc": "The absolute `file:` URL of the module."
            },
            {
              "textRaw": "Type: {boolean} `true` when the current module is the entry point of the current process; `false` otherwise.",
              "name": "main",
              "type": "boolean",
              "meta": {
                "added": [
                  "v24.2.0",
                  "v22.18.0"
                ],
                "changes": []
              },
              "stability": 1,
              "stabilityText": "Early development",
              "desc": "<p>Equivalent to <code>require.main === module</code> in CommonJS.</p>\n<p>Analogous to Python's <code>__name__ == \"__main__\"</code>.</p>\n<pre><code class=\"language-js\">export function foo() {\n  return 'Hello, world';\n}\n\nfunction main() {\n  const message = foo();\n  console.log(message);\n}\n\nif (import.meta.main) main();\n// `foo` can be imported from another module without possible side-effects from `main`\n</code></pre>",
              "shortDesc": "`true` when the current module is the entry point of the current process; `false` otherwise."
            }
          ],
          "methods": [
            {
              "textRaw": "`import.meta.resolve(specifier)`",
              "name": "resolve",
              "type": "method",
              "meta": {
                "added": [
                  "v13.9.0",
                  "v12.16.2"
                ],
                "changes": [
                  {
                    "version": [
                      "v20.6.0",
                      "v18.19.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/49028",
                    "description": "No longer behind `--experimental-import-meta-resolve` CLI flag, except for the non-standard `parentURL` parameter."
                  },
                  {
                    "version": [
                      "v20.6.0",
                      "v18.19.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/49038",
                    "description": "This API no longer throws when targeting `file:` URLs that do not map to an existing file on the local FS."
                  },
                  {
                    "version": [
                      "v20.0.0",
                      "v18.19.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/44710",
                    "description": "This API now returns a string synchronously instead of a Promise."
                  },
                  {
                    "version": [
                      "v16.2.0",
                      "v14.18.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/38587",
                    "description": "Add support for WHATWG `URL` object to `parentURL` parameter."
                  }
                ]
              },
              "stability": 1.2,
              "stabilityText": "Release candidate",
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`specifier` {string} The module specifier to resolve relative to the current module.",
                      "name": "specifier",
                      "type": "string",
                      "desc": "The module specifier to resolve relative to the current module."
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {string} The absolute URL string that the specifier would resolve to.",
                    "name": "return",
                    "type": "string",
                    "desc": "The absolute URL string that the specifier would resolve to."
                  }
                }
              ],
              "desc": "<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve\"><code>import.meta.resolve</code></a> is a module-relative resolution function scoped to\neach module, returning the URL string.</p>\n<pre><code class=\"language-js\">const dependencyAsset = import.meta.resolve('component-lib/asset.css');\n// file:///app/node_modules/component-lib/asset.css\nimport.meta.resolve('./dep.js');\n// file:///app/dep.js\n</code></pre>\n<p>All features of the Node.js module resolution are supported. Dependency\nresolutions are subject to the permitted exports resolutions within the package.</p>\n<p><strong>Caveats</strong>:</p>\n<ul>\n<li>This can result in synchronous file-system operations, which\ncan impact performance similarly to <code>require.resolve</code>.</li>\n<li>This feature is not available within custom loaders (it would\ncreate a deadlock).</li>\n</ul>\n<p><strong>Non-standard API</strong>:</p>\n<p>When using the <code>--experimental-import-meta-resolve</code> flag, that function accepts\na second argument:</p>\n<ul>\n<li><code>parent</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> | <a href=\"url.html#the-whatwg-url-api\"><code>&#x3C;URL></code></a> An optional absolute parent module URL to resolve from. <strong>Default:</strong> <code>import.meta.url</code></li>\n</ul>"
            }
          ]
        }
      ]
    }
  ]
}