rechoir is a utility designed to prepare the Node.js `require` environment for dynamically loading files with various non-native extensions. It operates by registering module loaders into `require.extensions`, leveraging `interpret`-like configuration objects to map file extensions to their respective transpiler or loader modules. Currently stable at version 0.8.0, releases are typically feature-driven and occur on an irregular cadence, often in conjunction with updates within the broader Gulp.js ecosystem where it serves as a dependency for tools like `liftoff`. A key differentiator is its ability to integrate with third-party transpilers (e.g., CoffeeScript, TypeScript, Babel) without bundling them, instead requiring developers to install these transpiler modules as local project dependencies. This design makes rechoir a flexible tool for command-line interfaces and build systems that need to process files written in languages other than standard JavaScript directly via Node's module resolution system.
npm install rechoirVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use rechoir with `interpret.extensions` to dynamically register and load files with custom extensions like `.coffee` and `.toml` into the Node.js runtime, allowing them to be `require()`-d like standard JavaScript modules. It highlights the need for local transpiler installations.
Upgrade Node.js to v10.13.0 or higher, or downgrade rechoir to v0.7.1.
Refer to the `rechoir` README for the correct `prepare(config, filepath, [cwd], [noThrow])` API usage and update your code accordingly.
Update transpiler configurations to align with Babel, using `.babel.js` if necessary, or ensure compatible Babel setups are in place.
Migrate usage from `load` to the `prepare` method, which became the primary API for registering module loaders.
Ensure that any required transpiler packages (e.g., `npm install coffee-script`) are installed in your project's `node_modules`.
Be mindful of other tools in your environment that might also modify `require.extensions`. Debug conflicts by inspecting `require.extensions` before and after `rechoir.prepare()` calls.
Install the missing transpiler package: `npm install coffee-script` (or the equivalent for other languages like `ts-node`, `@babel/register`, `toml`).
Ensure you are using `const rechoir = require('rechoir');` for CommonJS. If on an old version, update `rechoir` to >=0.5.0.Install the `interpret` package: `npm install interpret`.
Ensure `interpret` has a mapping for the desired extension, and that the specified loader module (e.g., `node-sass`) is installed. You might need to extend `interpret.extensions` or use a custom configuration object.