Converts source code to a reusable Node.js module at runtime. Version 2.0.28 (stable) is actively maintained. Supports synchronous and asynchronous loading from files or plain text, with built-in transpiler registration for JavaScript and JSON. Unlike vm.runInNewContext, it provides module caching, last-modified checks, and a familiar Node.js module environment. Key differentiator: full control over transpilation pipeline and context per loaded module, enabling custom transpilers (e.g., Babel, TypeScript) and virtual file paths with cache expiry.
npm install src-to-moduleNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows synchronous loading from file and from plain text string using src-to-module.
Use named imports: import { requireSync } from 'src-to-module' instead of const srcToModule = require('src-to-module').Use configuration: import { configure } from 'src-to-module'; configure({ checkLastModified: false }).Avoid naming your own global variables requireAsync. Alternatively, use a separate sandbox if available in future versions.
Provide a maxAge option (positive number) or call clearCache() to invalidate cache.
Use import { requireSync } from 'src-to-module' or const { requireSync } = require('src-to-module').Load the module with requireAsync to make the global requireAsync available.
Wrap your code in an async function, or use runAsync which adds async wrapper.
No dependency data recorded yet.