.mjs File Extension
.mjs file is, how to open ECMAScript modules, how Poly supports them, and when .js or .cjs is a better fit. File extension details for .mjs
Full Support| File type | ECMAScript module source file |
|---|---|
| MIME type | |
| Encoding | Unicode source text, normally UTF-8 |
| Operating systems | Windows, macOS, Linux, ChromeOS |
| Opens with | Visual Studio Code, WebStorm, Sublime Text, Node.js |
| Poly support | Yes. Poly supports readable .mjs source as text; supply text/javascript when a precise JavaScript label matters. |
| Indexed by Poly | Yes. Poly indexes readable source for exact and semantic search. |
| Preview in Poly | Yes. Readable .mjs files open in Poly's read-only code editor. |
| Poly agent | Yes. The Poly agent can read and reason about the source without executing it. |
What kind of file is a .mjs?
An .mjs file contains a JavaScript module, also called an ECMAScript module. It is Unicode source text and commonly uses import and export statements to share code between files. The suffix explicitly selects ECMAScript's Module grammar in environments that use extensions to choose how JavaScript is parsed.1
The registered MIME type is text/javascript. There is no magic byte sequence for .mjs, so a content check must decode the text and parse it as JavaScript rather than look for a fixed header.2
.js file to .mjs does not transform its source. It can still change how a runtime interprets the file, so check imports, exports, and CommonJS features before renaming.How do I open a .mjs on my computer?
Open .mjs files on Windows, macOS, Linux, or ChromeOS with a code editor such as Visual Studio Code, WebStorm, or Sublime Text. A basic text editor is enough for inspection, while a code editor adds syntax highlighting, diagnostics, and navigation.
Node.js treats .mjs as an explicit ECMAScript module marker. You can run a compatible entry point with node app.mjs; relative imports generally need their full filename, including the extension.3 Browsers load modules through <script type="module"> or import(). When an .mjs file is served over HTTP, the response must use a JavaScript MIME type such as text/javascript or strict module MIME checking can reject it.4
.mjs file merely to inspect it. Modules can import more code and use the filesystem, network, credentials, or page access granted by their runtime.Poly support for .mjs
Poly stores readable .mjs source, opens it in a read-only code editor, and makes its text available to exact and semantic search. The Poly agent can summarize exports, explain functions, and reason about the source without running it.
An .mjs filename may receive generic text handling unless the registered text/javascript MIME type is supplied. Either way, valid readable text can use Poly's text preview, indexing, and agent features. Poly does not execute modules, install packages, or automatically follow imports, and its preview is not a malware verdict.
History of .mjs
ECMAScript gained standardized modules in the sixth edition of ECMA-262 in 2015. A module and a classic script can contain overlapping source text, so content and MIME type alone cannot always select the correct grammar.1 The .mjs convention provides that missing signal.
Node.js added initial ECMAScript module support in version 8.5.0 and uses .mjs as one explicit way to select modules.3 RFC 9239 standardized the extension's meaning for interchange in 2022 and added .mjs to the text/javascript registration.1
Working with .mjs and alternatives
Choose a suffix that matches the runtime and project configuration:
| Extension | Typical meaning | Best fit |
|---|---|---|
.mjs | ECMAScript module | An explicit module signal independent of package.json type |
.js | JavaScript selected by host configuration | Browsers and projects that already define module mode |
.cjs | Node.js CommonJS module | Code that deliberately uses require() and module.exports |
.mts | TypeScript ECMAScript module | Typed source that will be checked and transformed |
For web deployment, configure the server to return Content-Type: text/javascript for .mjs. The URL suffix alone does not replace the response type in a browser. Keep dependency manifests and lockfiles with the source because a standalone module does not describe package versions or runtime permissions.
Converting CommonJS to an ECMAScript module can require replacing require() and module.exports, reviewing file-path globals, and testing dependency interoperability. Changing the filename alone does none of that work.
Footnotes
- Miller, M., Borins, M., Bynens, M., and B. Farias. RFC 9239: Updates to ECMAScript Media Types. Internet Engineering Task Force, May 2022. ↩ ↩2 ↩3
- Internet Assigned Numbers Authority. text/javascript Media Type Registration. ↩
- Node.js. Modules: ECMAScript Modules. ↩ ↩2
- WHATWG. HTML Standard: JavaScript Module Script Loading. ↩