Socket
Book a DemoInstallSign in
Socket

@node-loader/import-maps

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@node-loader/import-maps

A nodejs loader for import maps

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

@node-loader/import-maps

NodeJS customization hooks to add support for import maps to NodeJS. This allows you to customize module resolution by creating a node.importmap file.

Installation

npm install --save @node-loader/import-maps
pnpm install --save @node-loader/import-maps

Usage

Create a file (e.g. node.importmap) in the current working directory:

{
  "imports": {
    "my-module": "file:///home/name/code/my-module.js"
  }
}

Now create a file main.js that imports the mapped module:

import "my-module";

Now create a startup module register-hooks.js:

import { register } from "node:module";
import { MessageChannel } from "node:worker_threads";

const messageChannel = new MessageChannel();

global.importMapPort = messageChannel.port1;

register("@node-loader/import-maps", {
  data: {
    // optional, provides a way to update the import map later on
    port: messageChannel.port2,

    // optional, import map object
    importMap: {
      imports: {},
      scopes: {},
    },

    // optional, file url resolved relative to current working directory
    // This option is ignored if importMap is provided
    importMapUrl: "./node.importmap",
  },
  transferList: [messageChannel.port2],
});

Now run main.js with the --import NodeJS flag:

To dynamically change the import map after startup, do the following:

global.importMapPort.postMessage({
  // Provide either importMap or importMapUrl, but not both
  importMap: {
    imports: {},
    scopes: {},
  },

  importMapUrl: "./node.importmap",
});
node --import ./register-hooks.js main.js

FAQs

Package last updated on 07 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts