@humanwhocodes/module-importer
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The @humanwhocodes/module-importer is a powerful, versatile utility designed for Node.js. It allows for the seamless importation of modules, regardless of whether they’re in CommonJS or ESM format. This package leverages the ‘import()’ function and the inherent CommonJS compatibility of Node.js, ensuring the correct location and format are utilized. The key issue it addresses is the relative resolution of the standard ‘import()’. It provides a user-friendly way to resolve and import modules from any directory, negating any issues that might arise from compatibility differences between formats.
Using the @humanwhocodes/module-importer couldn't be simpler. You primarily need to install it via npm or yarn. Installation commands are 'npm install @humanwhocodes/module-importer' or 'yarn add @humanwhocodes/module-importer'. If using it for a Bun project, use the command 'bun add @humanwhocodes/module-importer'. To import it into your Node.js or Bun project, use the import command. For example, using ESM, type 'import { ModuleImporter } from "@humanwhocodes/module-importer";' or, for CommonJS, type 'const { ModuleImporter } = require("@humanwhocodes/module-importer");'. Once imported, create a new instance of ModuleImporter to start emitting events. Code usage could be something like this:
// cwd can be omitted to use process.cwd()
const importer = new ModuleImporter(cwd);
// you can resolve the location of any package
const location = importer.resolve("./some-file.cjs");
// you can also import directly
const module = importer.import("./some-file.cjs");
For comprehensive information, guides, and API details, the @humanwhocodes/module-importer's documentation can be located on its official Github repository, found at git+https://github.com/humanwhocodes/module-importer.git. By visiting the repository, users gain access to every detail from installation and usage guidance to developer setup and licensing information.