MJS JS
File conversion

Convert MJS to JS

QUICK ANSWER
Is it possible to convert MJS to JS?
Yes - MJS converts to JS.

The fastest path is to rename file.mjs to file.js; it stays an ES module only if your package.json has "type": "module". If it does not, Node will treat the .js file as CommonJS, so you must either add that field or transpile the import/export syntax to require/module.exports with Babel or esbuild.

Also to JS: WASM · AXD · FBA

On this page

Tested on macOS, Windows & Linux
Last verified Sep 2026

More free converters

HEIC, PNG, WEBP, MP3 and more - every tool here is free.

Open the toolbox

Why convert MJS to JS?

People convert .mjs to plain .js to drop the explicit ES-module extension and let the project's package.json decide the module system, or to ship CommonJS output that older Node versions and tools can load without ESM.

How to convert MJS to JS

Babel OPEN-SOURCE

Install @babel/plugin-transform-modules-commonjs (or @babel/preset-env) and run babel file.mjs --out-file file.js to rewrite import/export into CommonJS require/module.exports.

esbuild OPEN-SOURCE

Run esbuild file.mjs --format=cjs --platform=node --outfile=file.js to emit a CommonJS .js bundle from the ES module.

Visual Studio Code FREE

Open the .mjs in VS Code, rename it to .js, and use the editor to convert import/export statements by hand for small files.

About these formats

Quality & what to watch

  • Renaming alone does not change the code; if package.json is not set to "type": "module", ESM syntax in a .js file will throw a SyntaxError.
  • Transpiling to CommonJS changes import/export into require/module.exports and can alter top-level await and import.meta behavior.
  • A bundler like esbuild may inline dependencies and strip comments, so the output .js is not a line-for-line copy of the source.

Frequently asked questions

Is `.mjs` the same as `.js`?
Both are JavaScript. .mjs always means an ES module, while .js follows whatever package.json sets - CommonJS by default, or ESM if "type": "module" is present.
Can I just rename `.mjs` to `.js`?
Yes, but it stays a working ES module only if package.json has "type": "module". Otherwise Node treats the .js as CommonJS and ESM syntax will error.
How do I keep ESM after renaming?
Add "type": "module" to your package.json, or use the .mjs extension. Both tell Node to parse the file as an ES module.
Do I need Babel or esbuild?
Only if you want CommonJS output for older tooling. To keep ESM you just rename the file and set the package type.