Registry / testing / module-available

module-available

JSON →
library1.0.6jsnpmunverified

The `module-available` package provides a synchronous utility function to determine if a given Node.js module name can be successfully resolved and loaded using the `require` mechanism. The current stable version is 1.0.6, released in early 2016. The project appears to be unmaintained, with no updates in over eight years, making it an `abandoned` project. Its core function remains stable for its intended use case: checking the existence and resolvability of modules typically found in `node_modules` or built-in Node.js modules, without actually loading them. This differentiates it from simply attempting a `try/catch` around `require`, as it specifically checks *availability* rather than *loading success*. It strictly operates within the CommonJS module resolution context.

npm install module-available
INSTALL
IMPORT
SIG · MODULE-AVAILABLE
M
module-available
testingjavascriptv1.0.6
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

moduleAvailable
const moduleAvailable = require('module-available');
import moduleAvailable from 'module-available'; // OR import { moduleAvailable } from 'module-available';
This package is CommonJS-only and exports a default function. ESM `import` statements will fail.

This quickstart demonstrates how to use `module-available` to check for the presence of built-in Node.js modules and installed npm packages, both existing and non-existent, using CommonJS `require` syntax.

const moduleAvailable = require('module-available'); console.log("Checking module availability..."); // Check for a built-in Node.js module console.log(`'fs' module available: ${moduleAvailable('fs')}`); // Should be true // Check for an installed npm package (e.g., 'express') // You might need to `npm install express` for this to be true console.log(`'express' module available: ${moduleAvailable('express')}`); // Check for another installed npm package (e.g., 'lodash') // You might need to `npm install lodash` for this to be true console.log(`'lodash' module available: ${moduleAvailable('lodash')}`); // Check for a module that is definitely not installed console.log(`'non-existent-module-abc' available: ${moduleAvailable('non-existent-module-abc')}`); // Should be false // Note: This only checks for modules resolvable by 'require' and does not support ESM imports. // It also does not check for relative file paths.
Debug
Known issues
gotchaThis package is designed for CommonJS environments and uses `require`. It does not support ES Modules (ESM) `import` syntax directly and will not correctly resolve modules in an ESM context.
fix
For CommonJS, use `const moduleAvailable = require('module-available');`. For ESM projects, you would need an alternative solution or wrap `require` in a custom utility if you must use this package.
affects: >=1.0.0
gotchaThe `module-available` function checks for modules resolvable via Node.js's standard `require` paths (e.g., `node_modules` or built-in modules). It is not designed to resolve arbitrary relative file paths (e.g., `./my-local-file.js`).
fix
Ensure `moduleName` refers to an installed npm package name or a Node.js built-in module, not a relative path to a local file.
affects: >=1.0.0
gotchaThe project has been unmaintained since early 2016. While its simple functionality remains stable, there will be no further updates, bug fixes, or security patches. Consider this when integrating into new projects or long-term systems.
fix
Evaluate alternatives if active maintenance and modern module support (ESM) are critical requirements for your project.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , module_available_1.default) is not a function
Attempting to use `module-available` with ESM `import` syntax, which results in a default export being incorrectly accessed after transpilation.
fix
Use CommonJS `require` syntax: `const moduleAvailable = require('module-available');`.
ReferenceError: moduleAvailable is not defined
The `moduleAvailable` function was called without being properly imported or required, or the import/require statement failed.
fix
Verify the `require` statement is correct and executed before use: `const moduleAvailable = require('module-available');`.
Upgrade
Version history
1.0.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
module-available — npm install module-available · libregistry