Convert CommonJS require and module.exports to ES module import/export syntax and back for the common static patterns. CommonJS ⇄ ESM Converter is a free online tool from the ToolsRift JavaScript Tools collection. It runs entirely in your browser — nothing to install, no signup, and your data never leaves your device.
Loading CommonJS ⇄ ESM Converter…
How to use CommonJS ⇄ ESM Converter
Choose the conversion direction, paste your module code, then click Convert. Review the output — static require/import patterns are converted automatically.
Frequently asked questions
Which patterns are converted?
Default (const x = require('y')), named (const { a } = require('y')), side-effect (require('y')), module.exports and exports.foo — and the reverse import/export forms for ESM to CommonJS.
Does it convert dynamic require()?
No. Only static, top-level patterns are converted. Dynamic or conditional require() calls, re-exports (export ... from) and mixed default+named imports are left unchanged.
Is the output ready to run?
It handles the common cases but is a static text transform, not a bundler. Review edge cases such as interop defaults and mixed imports before shipping.
ToolsRift processes your files in your browser. We use cookies only for basic analytics and to support ads that keep every tool free. See our Cookie Policy.