
Security News
Next.js Patches Critical Middleware Vulnerability (CVE-2025-29927)
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
@humanwhocodes/module-importer
Advanced tools
If you find this useful, please consider supporting my work with a donation.
A utility for seamlessly importing modules in Node.js regardless if they are CommonJS or ESM format. Under the hood, this uses import()
and relies on Node.js's CommonJS compatibility to work correctly. This ensures that the correct locations and formats are used for CommonJS so you can call one method and not worry about any compatibility issues.
The problem with the default import()
is that it always resolves relative to the file location in which it is called. If you want to resolve from a different location, you need to jump through a few hoops to achieve that. This package makes it easy to both resolve and import modules from any directory.
npm install @humanwhocodes/module-importer
# or
yarn add @humanwhocodes/module-importer
Import into your Node.js project:
// CommonJS
const { ModuleImporter } = require("@humanwhocodes/module-importer");
// ESM
import { ModuleImporter } from "@humanwhocodes/module-importer";
Install using this command:
bun add @humanwhocodes/module-importer
Import into your Bun project:
import { ModuleImporter } from "@humanwhocodes/module-importer";
After importing, create a new instance of ModuleImporter
to start emitting events:
// 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 both resolve()
and import()
, you can pass in package names and filenames.
npm install
to setup dependenciesnpm test
to run testsApache 2.0
FAQs
Universal module importer for Node.js
The npm package @humanwhocodes/module-importer receives a total of 26,868,758 weekly downloads. As such, @humanwhocodes/module-importer popularity was classified as popular.
We found that @humanwhocodes/module-importer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.