rewrite-imports is a lightweight (349B) utility designed to transform ECMAScript `import` statements into CommonJS `require()` calls using regular expressions. As of its current stable version, 3.0.0, it provides a performant way to transpile modules at the string level, without relying on an Abstract Syntax Tree (AST) parser. This makes it extremely fast and suitable for build-time processing in environments where a full AST transformation is overkill or undesired. The package typically sees minor updates and patches, with major versions introducing breaking changes like the shift to named exports in v3.0.0. Its primary differentiator is its simplicity and reliance on RegExp, offering a niche solution for projects that need a quick, no-frills import rewriting mechanism, particularly for older Node.js environments (>=6) or browser environments with a `require` shim. Unlike full module bundlers or transpilers, it solely performs string replacement and does not provide a runtime or evaluate the transformed code.
npm install rewrite-importsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use the `rewrite` function to convert various ES import syntaxes into CommonJS require() statements.
Change `import rewrite from 'rewrite-imports'` to `import { rewrite } from 'rewrite-imports'` or `const rewrite = require('rewrite-imports')` to `const { rewrite } = require('rewrite-imports')`.No direct fix needed unless your build process relied on the forced semicolon. Review your linting rules if this causes issues.
If you relied on `interop`, you may need to manually manage default exports or adjust your custom `require` function (via the `fn` parameter) to handle interop behavior.
For highly complex codebases or strict accuracy, consider using an AST-based transpiler instead. For simpler cases, ensure `import` statements are clean and unambiguous.
Ensure your target runtime environment meets the Node.js `>=6.x` requirement or provides necessary polyfills/shims for browser compatibility.
Do not expect `rewrite-imports` to handle module loading or execution at runtime; it's designed for static code transformation.
Update your import statement to `import { rewrite } from 'rewrite-imports'` for ESM or `const { rewrite } = require('rewrite-imports')` for CommonJS.Review the original code for potential false positives where `import` keywords are used outside of actual module declarations. If this issue persists, consider using an AST-based transpiler for more robust code analysis.
No dependency data recorded yet.