Loading…

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
JS Variable Name Validator
Check whether a name is a valid JavaScript identifier and explain each problem — digits, symbols, spaces or reserved keywords
JS Quote Normalizer
Convert JavaScript string quotes between single and double, string, comment and regex aware, re-escaping quotes as needed
JSON Key Sorter
Recursively sort the keys of a JSON object alphabetically (ascending or descending) with configurable indentation
var to let / const
Replace the var keyword with let or const across your code, string, comment and regex aware so text like \
JavaScript Formatter
Beautify and format JavaScript code with proper indentation and structure for better readability
JavaScript Minifier
Minify JavaScript by removing whitespace, comments, and shortening variable names to reduce file size

← View all JavaScript ToolsBrowse all 1,100+ tools →