How to open .MJS files on Mac

To open .MJS files on Mac, to view or edit: Control-click the .mjs file → Open With → choose a code editor (or any text editor).

Step-by-step instructions

  1. To view or edit: Control-click the .mjs file → Open With → choose a code editor (or any text editor).
  2. To run with Node.js: open Terminal, cd to the file’s folder, and run: node yourfile.mjs.

Common issues

The file opens as plain text or “unknown file type”

Many systems don’t assign a default app for .mjs even though it’s just JavaScript source code.

  1. Open it with a code editor or any plain-text editor using “Open with”.
  2. If you work with .mjs frequently, set your preferred editor as the default app for this extension.

Node.js errors about modules (import/export not working)

Module behavior depends on how Node.js decides whether a file is an ES module; .mjs is one explicit signal to use the ES module loader.

  1. Confirm the file name ends with .mjs and run it as: node yourfile.mjs.
  2. If you copied code from a .js project, make sure it uses ES module syntax and that you are running it in a context that supports ESM.

Web/server MIME type problems when hosting .mjs

If a server sends the wrong JavaScript media type, browsers and tools may refuse to load it as expected.

  1. Configure your server to send a JavaScript media type such as text/javascript for .mjs responses.
  2. Verify the Content-Type header in your browser’s developer tools or network inspector.

Security note

.mjs files are executable code when run in a JavaScript runtime (for example, Node.js). Only execute .mjs files you trust, because they can read/write files or make network requests depending on what the script does.

Back to .MJS extension page