%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/doc/nodejs/api/
Upload File :
Create Path :
Current File : //usr/share/doc/nodejs/api/module.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <meta name="nodejs.org:node-version" content="v18.19.1">
  <title>Modules: `node:module` API | Node.js v18.19.1 Documentation</title>
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/hljs.css">
  <script async defer src="assets/api.js" type="text/javascript"></script>
  __JS_FLAVORED_DYNAMIC_CSS__
</head>
<body class="alt apidoc" id="api-section-module">
  <div id="content" class="clearfix">
    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="index.html" title="Go back to the home page">
          Node.js
        </a>
      </div>
      <ul>
<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
</ul>
<hr class="line"/>

<ul>
<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
<li><a href="console.html" class="nav-console">Console</a></li>
<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
<li><a href="dns.html" class="nav-dns">DNS</a></li>
<li><a href="domain.html" class="nav-domain">Domain</a></li>
<li><a href="errors.html" class="nav-errors">Errors</a></li>
<li><a href="events.html" class="nav-events">Events</a></li>
<li><a href="fs.html" class="nav-fs">File system</a></li>
<li><a href="globals.html" class="nav-globals">Globals</a></li>
<li><a href="http.html" class="nav-http">HTTP</a></li>
<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
<li><a href="https.html" class="nav-https">HTTPS</a></li>
<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
<li><a href="module.html" class="nav-module active">Modules: <code>node:module</code> API</a></li>
<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
<li><a href="net.html" class="nav-net">Net</a></li>
<li><a href="os.html" class="nav-os">OS</a></li>
<li><a href="path.html" class="nav-path">Path</a></li>
<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
<li><a href="process.html" class="nav-process">Process</a></li>
<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
<li><a href="readline.html" class="nav-readline">Readline</a></li>
<li><a href="repl.html" class="nav-repl">REPL</a></li>
<li><a href="report.html" class="nav-report">Report</a></li>
<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
<li><a href="stream.html" class="nav-stream">Stream</a></li>
<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
<li><a href="test.html" class="nav-test">Test runner</a></li>
<li><a href="timers.html" class="nav-timers">Timers</a></li>
<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
<li><a href="tty.html" class="nav-tty">TTY</a></li>
<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
<li><a href="url.html" class="nav-url">URL</a></li>
<li><a href="util.html" class="nav-util">Utilities</a></li>
<li><a href="v8.html" class="nav-v8">V8</a></li>
<li><a href="vm.html" class="nav-vm">VM</a></li>
<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
</ul>
<hr class="line"/>

<ul>
<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
</ul>

    </div>

    <div id="column1" data-id="module" class="interior">
      <header class="header">
        <div class="header-container">
          <h1>Node.js v18.19.1 documentation</h1>
          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
              <path fill="none" d="M0 0h24v24H0z" />
              <path d="M11.1 12.08c-2.33-4.51-.5-8.48.53-10.07C6.27 2.2 1.98 6.59 1.98 12c0 .14.02.28.02.42.62-.27 1.29-.42 2-.42 1.66 0 3.18.83 4.1 2.15A4.01 4.01 0 0111 18c0 1.52-.87 2.83-2.12 3.51.98.32 2.03.5 3.11.5 3.5 0 6.58-1.8 8.37-4.52-2.36.23-6.98-.97-9.26-5.41z"/>
              <path d="M7 16h-.18C6.4 14.84 5.3 14 4 14c-1.66 0-3 1.34-3 3s1.34 3 3 3h3c1.1 0 2-.9 2-2s-.9-2-2-2z"/>
            </svg>
            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
              <path d="M0 0h24v24H0z" fill="none" />
              <path d="M6.76 4.84l-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.41-1.79 1.79 1.41 1.41 1.79-1.79zm-3.21 13.7l1.79 1.8 1.41-1.41-1.8-1.79-1.4 1.4zM20 10.5v2h3v-2h-3zm-8-5c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-1 16.95h2V19.5h-2v2.95zm-7.45-3.91l1.41 1.41 1.79-1.8-1.41-1.41-1.79 1.8z"/>
            </svg>
          </button>
        </div>
        <div id="gtoc">
          <ul>
            <li class="pinned-header">Node.js v18.19.1</li>
            
    <li class="picker-header">
      <a href="#">
        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
        Table of contents
      </a>

      <div class="picker"><div class="toc"><ul>
<li><a href="#modules-nodemodule-api">Modules: <code>node:module</code> API</a><ul>
<li><a href="#the-module-object">The <code>Module</code> object</a><ul>
<li><a href="#modulebuiltinmodules"><code>module.builtinModules</code></a></li>
<li><a href="#modulecreaterequirefilename"><code>module.createRequire(filename)</code></a></li>
<li><a href="#moduleisbuiltinmodulename"><code>module.isBuiltin(moduleName)</code></a></li>
<li><a href="#moduleregisterspecifier-parenturl-options"><code>module.register(specifier[, parentURL][, options])</code></a></li>
<li><a href="#modulesyncbuiltinesmexports"><code>module.syncBuiltinESMExports()</code></a></li>
</ul>
</li>
<li><a href="#customization-hooks">Customization Hooks</a><ul>
<li><a href="#enabling">Enabling</a></li>
<li><a href="#chaining">Chaining</a></li>
<li><a href="#communication-with-module-customization-hooks">Communication with module customization hooks</a></li>
<li><a href="#hooks">Hooks</a><ul>
<li><a href="#initialize"><code>initialize()</code></a></li>
<li><a href="#resolvespecifier-context-nextresolve"><code>resolve(specifier, context, nextResolve)</code></a></li>
<li><a href="#loadurl-context-nextload"><code>load(url, context, nextLoad)</code></a></li>
<li><a href="#globalpreload"><code>globalPreload()</code></a></li>
</ul>
</li>
<li><a href="#examples">Examples</a><ul>
<li><a href="#import-from-https">Import from HTTPS</a></li>
<li><a href="#transpilation">Transpilation</a></li>
<li><a href="#import-maps">Import maps</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#source-map-v3-support">Source map v3 support</a><ul>
<li><a href="#modulefindsourcemappath"><code>module.findSourceMap(path)</code></a></li>
<li><a href="#class-modulesourcemap">Class: <code>module.SourceMap</code></a><ul>
<li><a href="#new-sourcemappayload"><code>new SourceMap(payload)</code></a></li>
<li><a href="#sourcemappayload"><code>sourceMap.payload</code></a></li>
<li><a href="#sourcemapfindentrylineoffset-columnoffset"><code>sourceMap.findEntry(lineOffset, columnOffset)</code></a></li>
<li><a href="#sourcemapfindoriginlinenumber-columnnumber"><code>sourceMap.findOrigin(lineNumber, columnNumber)</code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div></div>
    </li>
  
            
    <li class="picker-header">
      <a href="#">
        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
        Index
      </a>

      <div class="picker"><ul>
<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>

      <li>
        <a href="index.html">Index</a>
      </li>
    </ul>
  
<hr class="line"/>

<ul>
<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
<li><a href="console.html" class="nav-console">Console</a></li>
<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
<li><a href="dns.html" class="nav-dns">DNS</a></li>
<li><a href="domain.html" class="nav-domain">Domain</a></li>
<li><a href="errors.html" class="nav-errors">Errors</a></li>
<li><a href="events.html" class="nav-events">Events</a></li>
<li><a href="fs.html" class="nav-fs">File system</a></li>
<li><a href="globals.html" class="nav-globals">Globals</a></li>
<li><a href="http.html" class="nav-http">HTTP</a></li>
<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
<li><a href="https.html" class="nav-https">HTTPS</a></li>
<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
<li><a href="module.html" class="nav-module active">Modules: <code>node:module</code> API</a></li>
<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
<li><a href="net.html" class="nav-net">Net</a></li>
<li><a href="os.html" class="nav-os">OS</a></li>
<li><a href="path.html" class="nav-path">Path</a></li>
<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
<li><a href="process.html" class="nav-process">Process</a></li>
<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
<li><a href="readline.html" class="nav-readline">Readline</a></li>
<li><a href="repl.html" class="nav-repl">REPL</a></li>
<li><a href="report.html" class="nav-report">Report</a></li>
<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
<li><a href="stream.html" class="nav-stream">Stream</a></li>
<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
<li><a href="test.html" class="nav-test">Test runner</a></li>
<li><a href="timers.html" class="nav-timers">Timers</a></li>
<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
<li><a href="tty.html" class="nav-tty">TTY</a></li>
<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
<li><a href="url.html" class="nav-url">URL</a></li>
<li><a href="util.html" class="nav-util">Utilities</a></li>
<li><a href="v8.html" class="nav-v8">V8</a></li>
<li><a href="vm.html" class="nav-vm">VM</a></li>
<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
</ul>
<hr class="line"/>

<ul>
<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
</ul>
</div>
    </li>
  
            
    <li class="picker-header">
      <a href="#">
        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
        Other versions
      </a>
      <div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v18.x/api/module.html">18.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v17.x/api/module.html">17.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v16.x/api/module.html">16.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v15.x/api/module.html">15.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v14.x/api/module.html">14.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v13.x/api/module.html">13.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v12.x/api/module.html">12.x</a></li></ol></div>
    </li>
  
            <li class="picker-header">
              <a href="#">
                <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
                Options
              </a>
        
              <div class="picker">
                <ul>
                  <li>
                    <a href="all.html">View on single page</a>
                  </li>
                  <li>
                    <a href="module.json">View as JSON</a>
                  </li>
                  <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/module.md">Edit on GitHub</a></li>    
                </ul>
              </div>
            </li>
          </ul>
        </div>
        <hr>
      </header>

      <details id="toc" open><summary>Table of contents</summary><ul>
<li><a href="#modules-nodemodule-api">Modules: <code>node:module</code> API</a><ul>
<li><a href="#the-module-object">The <code>Module</code> object</a><ul>
<li><a href="#modulebuiltinmodules"><code>module.builtinModules</code></a></li>
<li><a href="#modulecreaterequirefilename"><code>module.createRequire(filename)</code></a></li>
<li><a href="#moduleisbuiltinmodulename"><code>module.isBuiltin(moduleName)</code></a></li>
<li><a href="#moduleregisterspecifier-parenturl-options"><code>module.register(specifier[, parentURL][, options])</code></a></li>
<li><a href="#modulesyncbuiltinesmexports"><code>module.syncBuiltinESMExports()</code></a></li>
</ul>
</li>
<li><a href="#customization-hooks">Customization Hooks</a><ul>
<li><a href="#enabling">Enabling</a></li>
<li><a href="#chaining">Chaining</a></li>
<li><a href="#communication-with-module-customization-hooks">Communication with module customization hooks</a></li>
<li><a href="#hooks">Hooks</a><ul>
<li><a href="#initialize"><code>initialize()</code></a></li>
<li><a href="#resolvespecifier-context-nextresolve"><code>resolve(specifier, context, nextResolve)</code></a></li>
<li><a href="#loadurl-context-nextload"><code>load(url, context, nextLoad)</code></a></li>
<li><a href="#globalpreload"><code>globalPreload()</code></a></li>
</ul>
</li>
<li><a href="#examples">Examples</a><ul>
<li><a href="#import-from-https">Import from HTTPS</a></li>
<li><a href="#transpilation">Transpilation</a></li>
<li><a href="#import-maps">Import maps</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#source-map-v3-support">Source map v3 support</a><ul>
<li><a href="#modulefindsourcemappath"><code>module.findSourceMap(path)</code></a></li>
<li><a href="#class-modulesourcemap">Class: <code>module.SourceMap</code></a><ul>
<li><a href="#new-sourcemappayload"><code>new SourceMap(payload)</code></a></li>
<li><a href="#sourcemappayload"><code>sourceMap.payload</code></a></li>
<li><a href="#sourcemapfindentrylineoffset-columnoffset"><code>sourceMap.findEntry(lineOffset, columnOffset)</code></a></li>
<li><a href="#sourcemapfindoriginlinenumber-columnnumber"><code>sourceMap.findOrigin(lineNumber, columnNumber)</code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</details>

      <div id="apicontent">
        <h2>Modules: <code>node:module</code> API<span><a class="mark" href="#modules-nodemodule-api" id="modules-nodemodule-api">#</a></span><a aria-hidden="true" class="legacy" id="module_modules_node_module_api"></a></h2>
<!--introduced_in=v12.20.0-->

<div class="api_metadata">
<span>Added in: v0.3.7</span>
</div><section><h3>The <code>Module</code> object<span><a class="mark" href="#the-module-object" id="the-module-object">#</a></span><a aria-hidden="true" class="legacy" id="module_the_module_object"></a></h3>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>Provides general utility methods when interacting with instances of
<code>Module</code>, the <a href="modules.html#the-module-object"><code>module</code></a> variable often seen in <a href="modules.html">CommonJS</a> modules. Accessed
via <code>import &#39;node:module&#39;</code> or <code>require(&#39;node:module&#39;)</code>.</p>
<h4><code>module.builtinModules</code><span><a class="mark" href="#modulebuiltinmodules" id="modulebuiltinmodules">#</a></span><a aria-hidden="true" class="legacy" id="module_module_builtinmodules"></a></h4>
<div class="api_metadata">
<span>Added in: v9.3.0, v8.10.0, v6.13.0</span>
</div><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a></li>
</ul>
<p>A list of the names of all modules provided by Node.js. Can be used to verify
if a module is maintained by a third party or not.</p>
<p><code>module</code> in this context isn&#39;t the same object that&#39;s provided
by the <a href="modules.html#the-module-wrapper">module wrapper</a>. To access it, require the <code>Module</code> module:</p>
<pre><code class="language-mjs">// module.mjs
// In an ECMAScript module
import { builtinModules as builtin } from &#39;node:module&#39;;
</code></pre>
<pre><code class="language-cjs">// module.cjs
// In a CommonJS module
const builtin = require(&#39;node:module&#39;).builtinModules;
</code></pre>
<h4><code>module.createRequire(filename)</code><span><a class="mark" href="#modulecreaterequirefilename" id="modulecreaterequirefilename">#</a></span><a aria-hidden="true" class="legacy" id="module_module_createrequire_filename"></a></h4>
<div class="api_metadata">
<span>Added in: v12.2.0</span>
</div><ul>
<li><code>filename</code> {string|URL} Filename to be used to construct the require
function. Must be a file URL object, file URL string, or absolute path
string.</li>
<li>Returns: <a href="modules.html#requireid" class="type">&lt;require&gt;</a> Require function</li>
</ul>
<pre><code class="language-mjs">import { createRequire } from &#39;node:module&#39;;
const require = createRequire(import.meta.url);

// sibling-module.js is a CommonJS module.
const siblingModule = require(&#39;./sibling-module&#39;);
</code></pre>
<h4><code>module.isBuiltin(moduleName)</code><span><a class="mark" href="#moduleisbuiltinmodulename" id="moduleisbuiltinmodulename">#</a></span><a aria-hidden="true" class="legacy" id="module_module_isbuiltin_modulename"></a></h4>
<div class="api_metadata">
<span>Added in: v18.6.0</span>
</div><ul>
<li><code>moduleName</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> name of the module</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> returns true if the module is builtin else returns false</li>
</ul>
<pre><code class="language-mjs">import { isBuiltin } from &#39;node:module&#39;;
isBuiltin(&#39;node:fs&#39;); // true
isBuiltin(&#39;fs&#39;); // true
isBuiltin(&#39;wss&#39;); // false
</code></pre>
<h4><code>module.register(specifier[, parentURL][, options])</code><span><a class="mark" href="#moduleregisterspecifier-parenturl-options" id="moduleregisterspecifier-parenturl-options">#</a></span><a aria-hidden="true" class="legacy" id="module_module_register_specifier_parenturl_options"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.19.0</td>
<td><p>Add support for WHATWG URL instances.</p>
</td></tr>
<tr><td>v18.19.0</td>
<td><p><span>Added in: v18.19.0</span></p>
</td></tr>
</table>
</details>
</div><blockquote>
<p>Stability: 1.1 - Active development</p>
</blockquote>
<ul>
<li><code>specifier</code> {string|URL} Customization hooks to be registered; this should be
the same string that would be passed to <code>import()</code>, except that if it is
relative, it is resolved relative to <code>parentURL</code>.</li>
<li><code>parentURL</code> {string|URL} If you want to resolve <code>specifier</code> relative to a base
URL, such as <code>import.meta.url</code>, you can pass that URL here. <strong>Default:</strong>
<code>&#39;data:&#39;</code></li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>data</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a> Any arbitrary, cloneable JavaScript value to pass into the
<a href="#initialize"><code>initialize</code></a> hook.</li>
<li><code>transferList</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object[]&gt;</a> <a href="worker_threads.html#portpostmessagevalue-transferlist">transferrable objects</a> to be passed into the
<code>initialize</code> hook.</li>
</ul>
</li>
</ul>
<p>Register a module that exports <a href="#customization-hooks">hooks</a> that customize Node.js module
resolution and loading behavior. See <a href="#customization-hooks">Customization hooks</a>.</p>
<h4><code>module.syncBuiltinESMExports()</code><span><a class="mark" href="#modulesyncbuiltinesmexports" id="modulesyncbuiltinesmexports">#</a></span><a aria-hidden="true" class="legacy" id="module_module_syncbuiltinesmexports"></a></h4>
<div class="api_metadata">
<span>Added in: v12.12.0</span>
</div><p>The <code>module.syncBuiltinESMExports()</code> method updates all the live bindings for
builtin <a href="esm.html">ES Modules</a> to match the properties of the <a href="modules.html">CommonJS</a> exports. It
does not add or remove exported names from the <a href="esm.html">ES Modules</a>.</p>
<pre><code class="language-js">const fs = require(&#39;node:fs&#39;);
const assert = require(&#39;node:assert&#39;);
const { syncBuiltinESMExports } = require(&#39;node:module&#39;);

fs.readFile = newAPI;

delete fs.readFileSync;

function newAPI() {
  // ...
}

fs.newAPI = newAPI;

syncBuiltinESMExports();

import(&#39;node:fs&#39;).then((esmFS) =&gt; {
  // It syncs the existing readFile property with the new value
  assert.strictEqual(esmFS.readFile, newAPI);
  // readFileSync has been deleted from the required fs
  assert.strictEqual(&#39;readFileSync&#39; in fs, false);
  // syncBuiltinESMExports() does not remove readFileSync from esmFS
  assert.strictEqual(&#39;readFileSync&#39; in esmFS, true);
  // syncBuiltinESMExports() does not add names
  assert.strictEqual(esmFS.newAPI, undefined);
});
</code></pre>
<p><i id="module_customization_hooks"></i></p>
</section><section><h3>Customization Hooks<span><a class="mark" href="#customization-hooks" id="customization-hooks">#</a></span><a aria-hidden="true" class="legacy" id="module_customization_hooks"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.19.0</td>
<td><p>Added <code>initialize</code> hook to replace <code>globalPreload</code>.</p>
</td></tr>
<tr><td>v18.6.0, v16.17.0</td>
<td><p>Add support for chaining loaders.</p>
</td></tr>
<tr><td>v16.12.0</td>
<td><p>Removed <code>getFormat</code>, <code>getSource</code>, <code>transformSource</code>, and <code>globalPreload</code>; added <code>load</code> hook and <code>getGlobalPreload</code> hook.</p>
</td></tr>
<tr><td>v8.8.0</td>
<td><p><span>Added in: v8.8.0</span></p>
</td></tr>
</table>
</details>
</div><blockquote>
<p>Stability: 1.1 - Active development</p>
</blockquote>
<!-- type=misc -->

<p><i id="enabling_module_customization_hooks"></i></p>
<h4>Enabling<span><a class="mark" href="#enabling" id="enabling">#</a></span><a aria-hidden="true" class="legacy" id="module_enabling"></a></h4>
<p>Module resolution and loading can be customized by registering a file which
exports a set of hooks. This can be done using the <a href="#moduleregisterspecifier-parenturl-options"><code>register</code></a> method
from <code>node:module</code>, which you can run before your application code by
using the <code>--import</code> flag:</p>
<pre><code class="language-bash">node --import ./register-hooks.js ./my-app.js
</code></pre>
<pre><code class="language-mjs">// register-hooks.js
import { register } from &#39;node:module&#39;;

register(&#39;./hooks.mjs&#39;, import.meta.url);
</code></pre>
<pre><code class="language-cjs">// register-hooks.js
const { register } = require(&#39;node:module&#39;);
const { pathToFileURL } = require(&#39;node:url&#39;);

register(&#39;./hooks.mjs&#39;, pathToFileURL(__filename));
</code></pre>
<p>The file passed to <code>--import</code> can also be an export from a dependency:</p>
<pre><code class="language-bash">node --import some-package/register ./my-app.js
</code></pre>
<p>Where <code>some-package</code> has an <a href="packages.html#exports"><code>&quot;exports&quot;</code></a> field defining the <code>/register</code>
export to map to a file that calls <code>register()</code>, like the following <code>register-hooks.js</code>
example.</p>
<p>Using <code>--import</code> ensures that the hooks are registered before any application
files are imported, including the entry point of the application. Alternatively,
<code>register</code> can be called from the entry point, but dynamic <code>import()</code> must be
used for any code that should be run after the hooks are registered:</p>
<pre><code class="language-mjs">import { register } from &#39;node:module&#39;;

register(&#39;http-to-https&#39;, import.meta.url);

// Because this is a dynamic `import()`, the `http-to-https` hooks will run
// to handle `./my-app.js` and any other files it imports or requires.
await import(&#39;./my-app.js&#39;);
</code></pre>
<pre><code class="language-cjs">const { register } = require(&#39;node:module&#39;);
const { pathToFileURL } = require(&#39;node:url&#39;);

register(&#39;http-to-https&#39;, pathToFileURL(__filename));

// Because this is a dynamic `import()`, the `http-to-https` hooks will run
// to handle `./my-app.js` and any other files it imports or requires.
import(&#39;./my-app.js&#39;);
</code></pre>
<p>In this example, we are registering the <code>http-to-https</code> hooks, but they will
only be available for subsequently imported modules—in this case, <code>my-app.js</code>
and anything it references via <code>import</code> (and optionally <code>require</code>). If the
<code>import(&#39;./my-app.js&#39;)</code> had instead been a static <code>import &#39;./my-app.js&#39;</code>, the
app would have <em>already</em> been loaded <strong>before</strong> the <code>http-to-https</code> hooks were
registered. This due to the ES modules specification, where static imports are
evaluated from the leaves of the tree first, then back to the trunk. There can
be static imports <em>within</em> <code>my-app.js</code>, which will not be evaluated until
<code>my-app.js</code> is dynamically imported.</p>
<p><code>my-app.js</code> can also be CommonJS. Customization hooks will run for any
modules that it references via <code>import</code> (and optionally <code>require</code>).</p>
<p>Finally, if all you want to do is register hooks before your app runs and you
don&#39;t want to create a separate file for that purpose, you can pass a <code>data:</code>
URL to <code>--import</code>:</p>
<pre><code class="language-bash">node --import &#39;data:text/javascript,import { register } from &quot;node:module&quot;; import { pathToFileURL } from &quot;node:url&quot;; register(&quot;http-to-https&quot;, pathToFileURL(&quot;./&quot;));&#39; ./my-app.js
</code></pre>
<h4>Chaining<span><a class="mark" href="#chaining" id="chaining">#</a></span><a aria-hidden="true" class="legacy" id="module_chaining"></a></h4>
<p>It&#39;s possible to call <code>register</code> more than once:</p>
<pre><code class="language-mjs">// entrypoint.mjs
import { register } from &#39;node:module&#39;;

register(&#39;./first.mjs&#39;, import.meta.url);
register(&#39;./second.mjs&#39;, import.meta.url);
await import(&#39;./my-app.mjs&#39;);
</code></pre>
<pre><code class="language-cjs">// entrypoint.cjs
const { register } = require(&#39;node:module&#39;);
const { pathToFileURL } = require(&#39;node:url&#39;);

const parentURL = pathToFileURL(__filename);
register(&#39;./first.mjs&#39;, parentURL);
register(&#39;./second.mjs&#39;, parentURL);
import(&#39;./my-app.mjs&#39;);
</code></pre>
<p>In this example, the registered hooks will form chains. If both <code>first.mjs</code> and
<code>second.mjs</code> define a <code>resolve</code> hook, both will be called, in the order they
were registered. The same applies to all the other hooks.</p>
<p>The registered hooks also affect <code>register</code> itself. In this example,
<code>second.mjs</code> will be resolved and loaded per the hooks registered by
<code>first.mjs</code>. This allows for things like writing hooks in non-JavaScript
languages, so long as an earlier registered loader is one that transpiles into
JavaScript.</p>
<p>The <code>register</code> method cannot be called from within the module that defines the
hooks.</p>
<h4>Communication with module customization hooks<span><a class="mark" href="#communication-with-module-customization-hooks" id="communication-with-module-customization-hooks">#</a></span><a aria-hidden="true" class="legacy" id="module_communication_with_module_customization_hooks"></a></h4>
<p>Module customization hooks run on a dedicated thread, separate from the main
thread that runs application code. This means mutating global variables won&#39;t
affect the other thread(s), and message channels must be used to communicate
between the threads.</p>
<p>The <code>register</code> method can be used to pass data to an <a href="#initialize"><code>initialize</code></a> hook. The
data passed to the hook may include transferrable objects like ports.</p>
<pre><code class="language-mjs">import { register } from &#39;node:module&#39;;
import { MessageChannel } from &#39;node:worker_threads&#39;;

// This example demonstrates how a message channel can be used to
// communicate with the hooks, by sending `port2` to the hooks.
const { port1, port2 } = new MessageChannel();

port1.on(&#39;message&#39;, (msg) =&gt; {
  console.log(msg);
});

register(&#39;./my-hooks.mjs&#39;, {
  parentURL: import.meta.url,
  data: { number: 1, port: port2 },
  transferList: [port2],
});
</code></pre>
<pre><code class="language-cjs">const { register } = require(&#39;node:module&#39;);
const { pathToFileURL } = require(&#39;node:url&#39;);
const { MessageChannel } = require(&#39;node:worker_threads&#39;);

// This example showcases how a message channel can be used to
// communicate with the hooks, by sending `port2` to the hooks.
const { port1, port2 } = new MessageChannel();

port1.on(&#39;message&#39;, (msg) =&gt; {
  console.log(msg);
});

register(&#39;./my-hooks.mjs&#39;, {
  parentURL: pathToFileURL(__filename),
  data: { number: 1, port: port2 },
  transferList: [port2],
});
</code></pre>
<h4>Hooks<span><a class="mark" href="#hooks" id="hooks">#</a></span><a aria-hidden="true" class="legacy" id="module_hooks"></a></h4>
<p>The <a href="#moduleregisterspecifier-parenturl-options"><code>register</code></a> method can be used to register a module that exports a set of
hooks. The hooks are functions that are called by Node.js to customize the
module resolution and loading process. The exported functions must have specific
names and signatures, and they must be exported as named exports.</p>
<pre><code class="language-mjs">export async function initialize({ number, port }) {
  // Receives data from `register`.
}

export async function resolve(specifier, context, nextResolve) {
  // Take an `import` or `require` specifier and resolve it to a URL.
}

export async function load(url, context, nextLoad) {
  // Take a resolved URL and return the source code to be evaluated.
}
</code></pre>
<p>Hooks are part of a chain, even if that chain consists of only one custom
(user-provided) hook and the default hook, which is always present. Hook
functions nest: each one must always return a plain object, and chaining happens
as a result of each function calling <code>next&lt;hookName&gt;()</code>, which is a reference to
the subsequent loader&#39;s hook.</p>
<p>A hook that returns a value lacking a required property triggers an exception. A
hook that returns without calling <code>next&lt;hookName&gt;()</code> <em>and</em> without returning
<code>shortCircuit: true</code> also triggers an exception. These errors are to help
prevent unintentional breaks in the chain. Return <code>shortCircuit: true</code> from a
hook to signal that the chain is intentionally ending at your hook.</p>
<p>Hooks are run in a separate thread, isolated from the main thread where
application code runs. That means it is a different <a href="https://tc39.es/ecma262/#realm">realm</a>. The hooks thread
may be terminated by the main thread at any time, so do not depend on
asynchronous operations (like <code>console.log</code>) to complete.</p>
<h5><code>initialize()</code><span><a class="mark" href="#initialize" id="initialize">#</a></span><a aria-hidden="true" class="legacy" id="module_initialize"></a></h5>
<div class="api_metadata">
<span>Added in: v18.19.0</span>
</div><blockquote>
<p>Stability: 1.1 - Active development</p>
</blockquote>
<ul>
<li><code>data</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&lt;any&gt;</a> The data from <code>register(loader, import.meta.url, { data })</code>.</li>
</ul>
<p>The <code>initialize</code> hook provides a way to define a custom function that runs in
the hooks thread when the hooks module is initialized. Initialization happens
when the hooks module is registered via <a href="#moduleregisterspecifier-parenturl-options"><code>register</code></a>.</p>
<p>This hook can receive data from a <a href="#moduleregisterspecifier-parenturl-options"><code>register</code></a> invocation, including
ports and other transferrable objects. The return value of <code>initialize</code> can be a
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&lt;Promise&gt;</a>, in which case it will be awaited before the main application thread
execution resumes.</p>
<p>Module customization code:</p>
<pre><code class="language-mjs">// path-to-my-hooks.js

export async function initialize({ number, port }) {
  port.postMessage(`increment: ${number + 1}`);
}
</code></pre>
<p>Caller code:</p>
<pre><code class="language-mjs">import assert from &#39;node:assert&#39;;
import { register } from &#39;node:module&#39;;
import { MessageChannel } from &#39;node:worker_threads&#39;;

// This example showcases how a message channel can be used to communicate
// between the main (application) thread and the hooks running on the hooks
// thread, by sending `port2` to the `initialize` hook.
const { port1, port2 } = new MessageChannel();

port1.on(&#39;message&#39;, (msg) =&gt; {
  assert.strictEqual(msg, &#39;increment: 2&#39;);
});

register(&#39;./path-to-my-hooks.js&#39;, {
  parentURL: import.meta.url,
  data: { number: 1, port: port2 },
  transferList: [port2],
});
</code></pre>
<pre><code class="language-cjs">const assert = require(&#39;node:assert&#39;);
const { register } = require(&#39;node:module&#39;);
const { pathToFileURL } = require(&#39;node:url&#39;);
const { MessageChannel } = require(&#39;node:worker_threads&#39;);

// This example showcases how a message channel can be used to communicate
// between the main (application) thread and the hooks running on the hooks
// thread, by sending `port2` to the `initialize` hook.
const { port1, port2 } = new MessageChannel();

port1.on(&#39;message&#39;, (msg) =&gt; {
  assert.strictEqual(msg, &#39;increment: 2&#39;);
});

register(&#39;./path-to-my-hooks.js&#39;, {
  parentURL: pathToFileURL(__filename),
  data: { number: 1, port: port2 },
  transferList: [port2],
});
</code></pre>
<h5><code>resolve(specifier, context, nextResolve)</code><span><a class="mark" href="#resolvespecifier-context-nextresolve" id="resolvespecifier-context-nextresolve">#</a></span><a aria-hidden="true" class="legacy" id="module_resolve_specifier_context_nextresolve"></a></h5>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.19.0</td>
<td><p>The property <code>context.importAssertions</code> is replaced with <code>context.importAttributes</code>. Using the old name is still supported and will emit an experimental warning.</p>
</td></tr>
<tr><td>v18.6.0, v16.17.0</td>
<td><p>Add support for chaining resolve hooks. Each hook must either call <code>nextResolve()</code> or include a <code>shortCircuit</code> property set to <code>true</code> in its return.</p>
</td></tr>
<tr><td>v17.1.0, v16.14.0</td>
<td><p>Add support for import assertions.</p>
</td></tr>
</table>
</details>
</div><blockquote>
<p>Stability: 1.2 - Release candidate</p>
</blockquote>
<ul>
<li><code>specifier</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>context</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>conditions</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> Export conditions of the relevant <code>package.json</code></li>
<li><code>importAttributes</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> An object whose key-value pairs represent the
attributes for the module to import</li>
<li><code>parentURL</code> {string|undefined} The module importing this one, or undefined
if this is the Node.js entry point</li>
</ul>
</li>
<li><code>nextResolve</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> The subsequent <code>resolve</code> hook in the chain, or the
Node.js default <code>resolve</code> hook after the last user-supplied <code>resolve</code> hook<ul>
<li><code>specifier</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>context</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
</li>
<li>Returns: {Object|Promise}<ul>
<li><code>format</code> {string|null|undefined} A hint to the load hook (it might be
ignored)
<code>&#39;builtin&#39; | &#39;commonjs&#39; | &#39;json&#39; | &#39;module&#39; | &#39;wasm&#39;</code></li>
<li><code>importAttributes</code> {Object|undefined} The import attributes to use when
caching the module (optional; if excluded the input will be used)</li>
<li><code>shortCircuit</code> {undefined|boolean} A signal that this hook intends to
terminate the chain of <code>resolve</code> hooks. <strong>Default:</strong> <code>false</code></li>
<li><code>url</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The absolute URL to which this input resolves</li>
</ul>
</li>
</ul>
<blockquote>
<p><strong>Warning</strong> Despite support for returning promises and async functions, calls
to <code>resolve</code> may block the main thread which can impact performance.</p>
</blockquote>
<p>The <code>resolve</code> hook chain is responsible for telling Node.js where to find and
how to cache a given <code>import</code> statement or expression, or <code>require</code> call. It can
optionally return a format (such as <code>&#39;module&#39;</code>) as a hint to the <code>load</code> hook. If
a format is specified, the <code>load</code> hook is ultimately responsible for providing
the final <code>format</code> value (and it is free to ignore the hint provided by
<code>resolve</code>); if <code>resolve</code> provides a <code>format</code>, a custom <code>load</code> hook is required
even if only to pass the value to the Node.js default <code>load</code> hook.</p>
<p>Import type attributes are part of the cache key for saving loaded modules into
the internal module cache. The <code>resolve</code> hook is responsible for returning an
<code>importAttributes</code> object if the module should be cached with different
attributes than were present in the source code.</p>
<p>The <code>conditions</code> property in <code>context</code> is an array of conditions for
<a href="packages.html#conditional-exports">package exports conditions</a> that apply to this resolution
request. They can be used for looking up conditional mappings elsewhere or to
modify the list when calling the default resolution logic.</p>
<p>The current <a href="packages.html#conditional-exports">package exports conditions</a> are always in
the <code>context.conditions</code> array passed into the hook. To guarantee <em>default
Node.js module specifier resolution behavior</em> when calling <code>defaultResolve</code>, the
<code>context.conditions</code> array passed to it <em>must</em> include <em>all</em> elements of the
<code>context.conditions</code> array originally passed into the <code>resolve</code> hook.</p>
<pre><code class="language-mjs">export async function resolve(specifier, context, nextResolve) {
  const { parentURL = null } = context;

  if (Math.random() &gt; 0.5) { // Some condition.
    // For some or all specifiers, do some custom logic for resolving.
    // Always return an object of the form {url: &lt;string&gt;}.
    return {
      shortCircuit: true,
      url: parentURL ?
        new URL(specifier, parentURL).href :
        new URL(specifier).href,
    };
  }

  if (Math.random() &lt; 0.5) { // Another condition.
    // When calling `defaultResolve`, the arguments can be modified. In this
    // case it&#39;s adding another value for matching conditional exports.
    return nextResolve(specifier, {
      ...context,
      conditions: [...context.conditions, &#39;another-condition&#39;],
    });
  }

  // Defer to the next hook in the chain, which would be the
  // Node.js default resolve if this is the last user-specified loader.
  return nextResolve(specifier);
}
</code></pre>
<h5><code>load(url, context, nextLoad)</code><span><a class="mark" href="#loadurl-context-nextload" id="loadurl-context-nextload">#</a></span><a aria-hidden="true" class="legacy" id="module_load_url_context_nextload"></a></h5>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.6.0, v16.17.0</td>
<td><p>Add support for chaining load hooks. Each hook must either call <code>nextLoad()</code> or include a <code>shortCircuit</code> property set to <code>true</code> in its return.</p>
</td></tr>
</table>
</details>
</div><blockquote>
<p>Stability: 1.2 - Release candidate</p>
</blockquote>
<ul>
<li><code>url</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The URL returned by the <code>resolve</code> chain</li>
<li><code>context</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>conditions</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> Export conditions of the relevant <code>package.json</code></li>
<li><code>format</code> {string|null|undefined} The format optionally supplied by the
<code>resolve</code> hook chain</li>
<li><code>importAttributes</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
</li>
<li><code>nextLoad</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> The subsequent <code>load</code> hook in the chain, or the
Node.js default <code>load</code> hook after the last user-supplied <code>load</code> hook<ul>
<li><code>specifier</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>context</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>format</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>shortCircuit</code> {undefined|boolean} A signal that this hook intends to
terminate the chain of <code>resolve</code> hooks. <strong>Default:</strong> <code>false</code></li>
<li><code>source</code> {string|ArrayBuffer|TypedArray} The source for Node.js to evaluate</li>
</ul>
</li>
</ul>
<p>The <code>load</code> hook provides a way to define a custom method of determining how a
URL should be interpreted, retrieved, and parsed. It is also in charge of
validating the import assertion.</p>
<p>The final value of <code>format</code> must be one of the following:</p>
<table>
<thead>
<tr>
<th><code>format</code></th>
<th>Description</th>
<th>Acceptable types for <code>source</code> returned by <code>load</code></th>
</tr>
</thead>
<tbody><tr>
<td><code>&#39;builtin&#39;</code></td>
<td>Load a Node.js builtin module</td>
<td>Not applicable</td>
</tr>
<tr>
<td><code>&#39;commonjs&#39;</code></td>
<td>Load a Node.js CommonJS module</td>
<td>Not applicable</td>
</tr>
<tr>
<td><code>&#39;json&#39;</code></td>
<td>Load a JSON file</td>
<td>{ <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer"><code>ArrayBuffer</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray"><code>TypedArray</code></a> }</td>
</tr>
<tr>
<td><code>&#39;module&#39;</code></td>
<td>Load an ES module</td>
<td>{ <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer"><code>ArrayBuffer</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray"><code>TypedArray</code></a> }</td>
</tr>
<tr>
<td><code>&#39;wasm&#39;</code></td>
<td>Load a WebAssembly module</td>
<td>{ <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer"><code>ArrayBuffer</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray"><code>TypedArray</code></a> }</td>
</tr>
</tbody></table>
<p>The value of <code>source</code> is ignored for type <code>&#39;builtin&#39;</code> because currently it is
not possible to replace the value of a Node.js builtin (core) module. The value
of <code>source</code> is ignored for type <code>&#39;commonjs&#39;</code> because the CommonJS module loader
does not provide a mechanism for the ES module loader to override the
<a href="esm.html#commonjs-namespaces">CommonJS module return value</a>. This limitation
might be overcome in the future.</p>
<blockquote>
<p><strong>Warning</strong>: The ESM <code>load</code> hook and namespaced exports from CommonJS modules
are incompatible. Attempting to use them together will result in an empty
object from the import. This may be addressed in the future.</p>
</blockquote>
<blockquote>
<p>These types all correspond to classes defined in ECMAScript.</p>
</blockquote>
<ul>
<li>The specific <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer"><code>ArrayBuffer</code></a> object is a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer"><code>SharedArrayBuffer</code></a>.</li>
<li>The specific <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray"><code>TypedArray</code></a> object is a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array"><code>Uint8Array</code></a>.</li>
</ul>
<p>If the source value of a text-based format (i.e., <code>&#39;json&#39;</code>, <code>&#39;module&#39;</code>)
is not a string, it is converted to a string using <a href="util.html#class-utiltextdecoder"><code>util.TextDecoder</code></a>.</p>
<p>The <code>load</code> hook provides a way to define a custom method for retrieving the
source code of a resolved URL. This would allow a loader to potentially avoid
reading files from disk. It could also be used to map an unrecognized format to
a supported one, for example <code>yaml</code> to <code>module</code>.</p>
<pre><code class="language-mjs">export async function load(url, context, nextLoad) {
  const { format } = context;

  if (Math.random() &gt; 0.5) { // Some condition
    /*
      For some or all URLs, do some custom logic for retrieving the source.
      Always return an object of the form {
        format: &lt;string&gt;,
        source: &lt;string|buffer&gt;,
      }.
    */
    return {
      format,
      shortCircuit: true,
      source: &#39;...&#39;,
    };
  }

  // Defer to the next hook in the chain.
  return nextLoad(url);
}
</code></pre>
<p>In a more advanced scenario, this can also be used to transform an unsupported
source to a supported one (see <a href="#examples">Examples</a> below).</p>
<h5><code>globalPreload()</code><span><a class="mark" href="#globalpreload" id="globalpreload">#</a></span><a aria-hidden="true" class="legacy" id="module_globalpreload"></a></h5>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.6.0, v16.17.0</td>
<td><p>Add support for chaining globalPreload hooks.</p>
</td></tr>
</table>
</details>
</div><blockquote>
<p>Stability: 1.0 - Early development</p>
</blockquote>
<blockquote>
<p><strong>Warning:</strong> This hook will be removed in a future version. Use
<a href="#initialize"><code>initialize</code></a> instead. When a hooks module has an <code>initialize</code> export,
<code>globalPreload</code> will be ignored.</p>
</blockquote>
<ul>
<li><code>context</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> Information to assist the preload code<ul>
<li><code>port</code> <a href="worker_threads.html#class-messageport" class="type">&lt;MessagePort&gt;</a></li>
</ul>
</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Code to run before application startup</li>
</ul>
<p>Sometimes it might be necessary to run some code inside of the same global
scope that the application runs in. This hook allows the return of a string
that is run as a sloppy-mode script on startup.</p>
<p>Similar to how CommonJS wrappers work, the code runs in an implicit function
scope. The only argument is a <code>require</code>-like function that can be used to load
builtins like &quot;fs&quot;: <code>getBuiltin(request: string)</code>.</p>
<p>If the code needs more advanced <code>require</code> features, it has to construct
its own <code>require</code> using  <code>module.createRequire()</code>.</p>
<pre><code class="language-mjs">export function globalPreload(context) {
  return `\
globalThis.someInjectedProperty = 42;
console.log(&#39;I just set some globals!&#39;);

const { createRequire } = getBuiltin(&#39;module&#39;);
const { cwd } = getBuiltin(&#39;process&#39;);

const require = createRequire(cwd() + &#39;/&lt;preload&gt;&#39;);
// [...]
`;
}
</code></pre>
<p>Another argument is provided to the preload code: <code>port</code>. This is available as a
parameter to the hook and inside of the source text returned by the hook. This
functionality has been moved to the <code>initialize</code> hook.</p>
<p>Care must be taken in order to properly call <a href="worker_threads.html#portref"><code>port.ref()</code></a> and
<a href="worker_threads.html#portunref"><code>port.unref()</code></a> to prevent a process from being in a state where it won&#39;t
close normally.</p>
<pre><code class="language-mjs">/**
 * This example has the application context send a message to the hook
 * and sends the message back to the application context
 */
export function globalPreload({ port }) {
  port.on(&#39;message&#39;, (msg) =&gt; {
    port.postMessage(msg);
  });
  return `\
    port.postMessage(&#39;console.log(&quot;I went to the hook and back&quot;);&#39;);
    port.on(&#39;message&#39;, (msg) =&gt; {
      eval(msg);
    });
  `;
}
</code></pre>
<h4>Examples<span><a class="mark" href="#examples" id="examples">#</a></span><a aria-hidden="true" class="legacy" id="module_examples"></a></h4>
<p>The various module customization hooks can be used together to accomplish
wide-ranging customizations of the Node.js code loading and evaluation
behaviors.</p>
<h5>Import from HTTPS<span><a class="mark" href="#import-from-https" id="import-from-https">#</a></span><a aria-hidden="true" class="legacy" id="module_import_from_https"></a></h5>
<p>In current Node.js, specifiers starting with <code>https://</code> are experimental (see
<a href="esm.html#https-and-http-imports">HTTPS and HTTP imports</a>).</p>
<p>The hook below registers hooks to enable rudimentary support for such
specifiers. While this may seem like a significant improvement to Node.js core
functionality, there are substantial downsides to actually using these hooks:
performance is much slower than loading files from disk, there is no caching,
and there is no security.</p>
<pre><code class="language-mjs">// https-hooks.mjs
import { get } from &#39;node:https&#39;;

export function load(url, context, nextLoad) {
  // For JavaScript to be loaded over the network, we need to fetch and
  // return it.
  if (url.startsWith(&#39;https://&#39;)) {
    return new Promise((resolve, reject) =&gt; {
      get(url, (res) =&gt; {
        let data = &#39;&#39;;
        res.setEncoding(&#39;utf8&#39;);
        res.on(&#39;data&#39;, (chunk) =&gt; data += chunk);
        res.on(&#39;end&#39;, () =&gt; resolve({
          // This example assumes all network-provided JavaScript is ES module
          // code.
          format: &#39;module&#39;,
          shortCircuit: true,
          source: data,
        }));
      }).on(&#39;error&#39;, (err) =&gt; reject(err));
    });
  }

  // Let Node.js handle all other URLs.
  return nextLoad(url);
}
</code></pre>
<pre><code class="language-mjs">// main.mjs
import { VERSION } from &#39;https://coffeescript.org/browser-compiler-modern/coffeescript.js&#39;;

console.log(VERSION);
</code></pre>
<p>With the preceding hooks module, running
<code>node --import &#39;data:text/javascript,import { register } from &quot;node:module&quot;; import { pathToFileURL } from &quot;node:url&quot;; register(pathToFileURL(&quot;./https-hooks.mjs&quot;));&#39; ./main.mjs</code>
prints the current version of CoffeeScript per the module at the URL in
<code>main.mjs</code>.</p>
<h5>Transpilation<span><a class="mark" href="#transpilation" id="transpilation">#</a></span><a aria-hidden="true" class="legacy" id="module_transpilation"></a></h5>
<p>Sources that are in formats Node.js doesn&#39;t understand can be converted into
JavaScript using the <a href="#loadurl-context-nextload"><code>load</code> hook</a>.</p>
<p>This is less performant than transpiling source files before running Node.js;
transpiler hooks should only be used for development and testing purposes.</p>
<pre><code class="language-mjs">// coffeescript-hooks.mjs
import { readFile } from &#39;node:fs/promises&#39;;
import { dirname, extname, resolve as resolvePath } from &#39;node:path&#39;;
import { cwd } from &#39;node:process&#39;;
import { fileURLToPath, pathToFileURL } from &#39;node:url&#39;;
import coffeescript from &#39;coffeescript&#39;;

const extensionsRegex = /\.(coffee|litcoffee|coffee\.md)$/;

export async function load(url, context, nextLoad) {
  if (extensionsRegex.test(url)) {
    // CoffeeScript files can be either CommonJS or ES modules, so we want any
    // CoffeeScript file to be treated by Node.js the same as a .js file at the
    // same location. To determine how Node.js would interpret an arbitrary .js
    // file, search up the file system for the nearest parent package.json file
    // and read its &quot;type&quot; field.
    const format = await getPackageType(url);

    const { source: rawSource } = await nextLoad(url, { ...context, format });
    // This hook converts CoffeeScript source code into JavaScript source code
    // for all imported CoffeeScript files.
    const transformedSource = coffeescript.compile(rawSource.toString(), url);

    return {
      format,
      shortCircuit: true,
      source: transformedSource,
    };
  }

  // Let Node.js handle all other URLs.
  return nextLoad(url);
}

async function getPackageType(url) {
  // `url` is only a file path during the first iteration when passed the
  // resolved url from the load() hook
  // an actual file path from load() will contain a file extension as it&#39;s
  // required by the spec
  // this simple truthy check for whether `url` contains a file extension will
  // work for most projects but does not cover some edge-cases (such as
  // extensionless files or a url ending in a trailing space)
  const isFilePath = !!extname(url);
  // If it is a file path, get the directory it&#39;s in
  const dir = isFilePath ?
    dirname(fileURLToPath(url)) :
    url;
  // Compose a file path to a package.json in the same directory,
  // which may or may not exist
  const packagePath = resolvePath(dir, &#39;package.json&#39;);
  // Try to read the possibly nonexistent package.json
  const type = await readFile(packagePath, { encoding: &#39;utf8&#39; })
    .then((filestring) =&gt; JSON.parse(filestring).type)
    .catch((err) =&gt; {
      if (err?.code !== &#39;ENOENT&#39;) console.error(err);
    });
  // Ff package.json existed and contained a `type` field with a value, voila
  if (type) return type;
  // Otherwise, (if not at the root) continue checking the next directory up
  // If at the root, stop and return false
  return dir.length &gt; 1 &amp;&amp; getPackageType(resolvePath(dir, &#39;..&#39;));
}
</code></pre>
<pre><code class="language-coffee"># main.coffee
import { scream } from &#39;./scream.coffee&#39;
console.log scream &#39;hello, world&#39;

import { version } from &#39;node:process&#39;
console.log &quot;Brought to you by Node.js version #{version}&quot;
</code></pre>
<pre><code class="language-coffee"># scream.coffee
export scream = (str) -&gt; str.toUpperCase()
</code></pre>
<p>With the preceding hooks module, running
<code>node --import &#39;data:text/javascript,import { register } from &quot;node:module&quot;; import { pathToFileURL } from &quot;node:url&quot;; register(pathToFileURL(&quot;./coffeescript-hooks.mjs&quot;));&#39; ./main.coffee</code>
causes <code>main.coffee</code> to be turned into JavaScript after its source code is
loaded from disk but before Node.js executes it; and so on for any <code>.coffee</code>,
<code>.litcoffee</code> or <code>.coffee.md</code> files referenced via <code>import</code> statements of any
loaded file.</p>
<h5>Import maps<span><a class="mark" href="#import-maps" id="import-maps">#</a></span><a aria-hidden="true" class="legacy" id="module_import_maps"></a></h5>
<p>The previous two examples defined <code>load</code> hooks. This is an example of a
<code>resolve</code> hook. This hooks module reads an <code>import-map.json</code> file that defines
which specifiers to override to other URLs (this is a very simplistic
implementation of a small subset of the &quot;import maps&quot; specification).</p>
<pre><code class="language-mjs">// import-map-hooks.js
import fs from &#39;node:fs/promises&#39;;

const { imports } = JSON.parse(await fs.readFile(&#39;import-map.json&#39;));

export async function resolve(specifier, context, nextResolve) {
  if (Object.hasOwn(imports, specifier)) {
    return nextResolve(imports[specifier], context);
  }

  return nextResolve(specifier, context);
}
</code></pre>
<p>With these files:</p>
<pre><code class="language-mjs">// main.js
import &#39;a-module&#39;;
</code></pre>
<pre><code class="language-json">// import-map.json
{
  &quot;imports&quot;: {
    &quot;a-module&quot;: &quot;./some-module.js&quot;
  }
}
</code></pre>
<pre><code class="language-mjs">// some-module.js
console.log(&#39;some module!&#39;);
</code></pre>
<p>Running <code>node --import &#39;data:text/javascript,import { register } from &quot;node:module&quot;; import { pathToFileURL } from &quot;node:url&quot;; register(pathToFileURL(&quot;./import-map-hooks.js&quot;));&#39; main.js</code>
should print <code>some module!</code>.</p>
</section><section><h3>Source map v3 support<span><a class="mark" href="#source-map-v3-support" id="source-map-v3-support">#</a></span><a aria-hidden="true" class="legacy" id="module_source_map_v3_support"></a></h3>
<div class="api_metadata">
<span>Added in: v13.7.0, v12.17.0</span>
</div><blockquote>
<p>Stability: 1 - Experimental</p>
</blockquote>
<p>Helpers for interacting with the source map cache. This cache is
populated when source map parsing is enabled and
<a href="https://sourcemaps.info/spec.html#h.lmz475t4mvbx">source map include directives</a> are found in a modules&#39; footer.</p>
<p>To enable source map parsing, Node.js must be run with the flag
<a href="cli.html#--enable-source-maps"><code>--enable-source-maps</code></a>, or with code coverage enabled by setting
<a href="cli.html#node_v8_coveragedir"><code>NODE_V8_COVERAGE=dir</code></a>.</p>
<pre><code class="language-mjs">// module.mjs
// In an ECMAScript module
import { findSourceMap, SourceMap } from &#39;node:module&#39;;
</code></pre>
<pre><code class="language-cjs">// module.cjs
// In a CommonJS module
const { findSourceMap, SourceMap } = require(&#39;node:module&#39;);
</code></pre>
<!-- Anchors to make sure old links find a target -->

<p><a id="module_module_findsourcemap_path_error"></a></p>
<h4><code>module.findSourceMap(path)</code><span><a class="mark" href="#modulefindsourcemappath" id="modulefindsourcemappath">#</a></span><a aria-hidden="true" class="legacy" id="module_module_findsourcemap_path"></a></h4>
<div class="api_metadata">
<span>Added in: v13.7.0, v12.17.0</span>
</div><ul>
<li><code>path</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li>Returns: {module.SourceMap|undefined} Returns <code>module.SourceMap</code> if a source
map is found, <code>undefined</code> otherwise.</li>
</ul>
<p><code>path</code> is the resolved path for the file for which a corresponding source map
should be fetched.</p>
<h4>Class: <code>module.SourceMap</code><span><a class="mark" href="#class-modulesourcemap" id="class-modulesourcemap">#</a></span><a aria-hidden="true" class="legacy" id="module_class_module_sourcemap"></a></h4>
<div class="api_metadata">
<span>Added in: v13.7.0, v12.17.0</span>
</div><h5><code>new SourceMap(payload)</code><span><a class="mark" href="#new-sourcemappayload" id="new-sourcemappayload">#</a></span><a aria-hidden="true" class="legacy" id="module_new_sourcemap_payload"></a></h5>
<ul>
<li><code>payload</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>Creates a new <code>sourceMap</code> instance.</p>
<p><code>payload</code> is an object with keys matching the <a href="https://sourcemaps.info/spec.html#h.mofvlxcwqzej">Source map v3 format</a>:</p>
<ul>
<li><code>file</code>: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>version</code>: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>sources</code>: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a></li>
<li><code>sourcesContent</code>: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a></li>
<li><code>names</code>: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a></li>
<li><code>mappings</code>: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>sourceRoot</code>: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<h5><code>sourceMap.payload</code><span><a class="mark" href="#sourcemappayload" id="sourcemappayload">#</a></span><a aria-hidden="true" class="legacy" id="module_sourcemap_payload"></a></h5>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>Getter for the payload used to construct the <a href="#class-modulesourcemap"><code>SourceMap</code></a> instance.</p>
<h5><code>sourceMap.findEntry(lineOffset, columnOffset)</code><span><a class="mark" href="#sourcemapfindentrylineoffset-columnoffset" id="sourcemapfindentrylineoffset-columnoffset">#</a></span><a aria-hidden="true" class="legacy" id="module_sourcemap_findentry_lineoffset_columnoffset"></a></h5>
<ul>
<li><code>lineOffset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The zero-indexed line number offset in
the generated source</li>
<li><code>columnOffset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The zero-indexed column number offset
in the generated source</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>Given a line offset and column offset in the generated source
file, returns an object representing the SourceMap range in the
original file if found, or an empty object if not.</p>
<p>The object returned contains the following keys:</p>
<ul>
<li>generatedLine: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The line offset of the start of the
range in the generated source</li>
<li>generatedColumn: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The column offset of start of the
range in the generated source</li>
<li>originalSource: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The file name of the original source,
as reported in the SourceMap</li>
<li>originalLine: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The line offset of the start of the
range in the original source</li>
<li>originalColumn: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The column offset of start of the
range in the original source</li>
<li>name: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>The returned value represents the raw range as it appears in the
SourceMap, based on zero-indexed offsets, <em>not</em> 1-indexed line and
column numbers as they appear in Error messages and CallSite
objects.</p>
<p>To get the corresponding 1-indexed line and column numbers from a
lineNumber and columnNumber as they are reported by Error stacks
and CallSite objects, use <code>sourceMap.findOrigin(lineNumber, columnNumber)</code></p>
<h5><code>sourceMap.findOrigin(lineNumber, columnNumber)</code><span><a class="mark" href="#sourcemapfindoriginlinenumber-columnnumber" id="sourcemapfindoriginlinenumber-columnnumber">#</a></span><a aria-hidden="true" class="legacy" id="module_sourcemap_findorigin_linenumber_columnnumber"></a></h5>
<ul>
<li><code>lineNumber</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The 1-indexed line number of the call
site in the generated source</li>
<li><code>columnOffset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The 1-indexed column number
of the call site in the generated source</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>Given a 1-indexed lineNumber and columnNumber from a call site in
the generated source, find the corresponding call site location
in the original source.</p>
<p>If the lineNumber and columnNumber provided are not found in any
source map, then an empty object is returned.  Otherwise, the
returned object contains the following keys:</p>
<ul>
<li>name: {string | undefined} The name of the range in the
source map, if one was provided</li>
<li>fileName: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The file name of the original source, as
reported in the SourceMap</li>
<li>lineNumber: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The 1-indexed lineNumber of the
corresponding call site in the original source</li>
<li>columnNumber: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The 1-indexed columnNumber of the
corresponding call site in the original source</li>
</ul>
</section>
        <!-- API END -->
      </div>
    </div>
  </div>
</body>
</html>

Zerion Mini Shell 1.0