CommonJS ⇄ ESM Converter — Free Online Tool

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.

More JavaScript Tools

JS String Escaper
Escape raw text into a valid JavaScript string literal (\\n, \\t, quotes, control chars) or unescape a literal back to plain text
JS Unicode Escaper
Escape non-ASCII characters to \\uXXXX sequences so source stays ASCII-safe, or decode \\uXXXX, \\u{...} and \\xXX back to text
JS Regex Escaper
Escape a literal string so its special characters are matched literally inside a RegExp, with optional forward-slash escaping
Template Literal → Concat
Convert ES6 template literals with ${expr} interpolation into equivalent string concatenation, string and regex aware
Ternary to If/Else
Expand ternary assignments, declarations and returns into readable if/else blocks, safely skipping ?? and ?. operators
List to JS Array
Turn a list of lines, comma or space separated values into a JavaScript array literal with quoting, trimming and de-duplication

← View all JavaScript Tools