require-addon (version 1.2.0) is a JavaScript utility designed to facilitate the loading of native C++ addons (typically compiled as `.node` files) across various JavaScript runtimes. Its primary function is to extend the standard CommonJS `require` function by adding an `.addon` method. This package simplifies the complex process of locating and loading precompiled or dynamically compiled native modules, particularly in environments beyond standard Node.js, such as the 'bare' engine utilized within the Holepunch/Hypercore ecosystem. It aims to provide a standardized interface for consuming native bindings, abstracting away some of the underlying system-specific calls and linking complexities. The package's release cadence appears to be infrequent, which is common for foundational libraries serving a specific, critical infrastructure role. Its key differentiator is its cross-runtime compatibility, making it suitable for specialized environments where direct native module integration is essential.
npm install require-addonVerified import paths — ran on the pinned version, not inferred.
Demonstrates the setup and basic usage of `require-addon` to load a native C++ module.
Be aware of potential conflicts and ensure `require-addon` is initialized early or in an isolated context if global modification is a concern. Consider wrapping its usage if strict modularity is required.
Ensure your native addon is compiled against the correct Node.js version and target environment (e.g., using `node-gyp rebuild --target=<NODE_VERSION>`). Verify that the compiled `.node` file is present in the expected location and matches the runtime's requirements.
Always use `const addonLoader = require('require-addon');` to import the module. If working in a pure ESM environment, you might need to use `createRequire` from the `module` built-in, though `require-addon`'s global modification pattern might still pose challenges.Ensure your Bare engine runtime meets the minimum version requirement. Upgrade your Bare engine instance if necessary to `1.10.0` or higher.
Ensure `const addonLoader = require('require-addon'); require.addon = addonLoader;` is executed before any calls to `require.addon(...)`.Verify the native addon is correctly compiled for your system (OS, architecture, Node.js version) and located in the directory passed to `require.addon`. Rebuild the addon if necessary.
Use CommonJS `require()` syntax: `const addonLoader = require('require-addon');`. In strict ESM, consider `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const addonLoader = require('require-addon');` although the global `require.addon` modification might still be problematic.No dependency data recorded yet.