ESM ↔ CommonJS Converter
Convert between ES modules and CommonJS syntax online
ESM (import/export)
CommonJS (require)
Converted code will appear here
Conversion reference
ESM → CommonJS
import foo from 'bar'→const foo = require('bar')
import { a, b } from 'bar'→const { a, b } = require('bar')
import * as ns from 'bar'→const ns = require('bar')
import 'bar'→require('bar')
export default foo→module.exports = foo
export const x = 1→const x = 1; exports.x = x
export function f() {}→function f() {} exports.f = f
export { a } from 'b'→exports.a = require('b').a
CommonJS → ESM
const foo = require('bar')→import foo from 'bar'
const { a } = require('bar')→import { a } from 'bar'
require('bar')→import 'bar'
module.exports = foo→export default foo
exports.x = x→export const x = x
Frequently asked questions
What does ESM ↔ CommonJS Converter do?
Convert between ES modules and CommonJS syntax online
What should I check in the result?
Test a small known example and an invalid input. Review generated code or decoded data before using it in a project; inspection alone does not establish correctness or authenticity.