.MJS

File MJS

Node.js ES Module File
Fai una domanda
RISPOSTA RAPIDA

Un file .mjs è codice sorgente JavaScript che Node.js tratta come un modulo ECMAScript, il che significa che utilizza import ed export invece del require di CommonJS. L'estensione esiste affinché Node possa distinguere i moduli ES dai vecchi file CommonJS senza controllare il file package.json. Poiché si tratta di testo semplice, puoi aprire e modificare un file .mjs in qualsiasi editor di codice come Visual Studio Code, Sublime Text o Vim, ed eseguirlo con node file.mjs.

Sviluppatore: Node.js Foundation / OpenJS Foundation (Ecma International for ECMAScript) Categoria: File di sviluppo Standard aperto MIME: text/javascript
SI APRE SU Windows macOS Linux Web
Correlati: .DO · .MD · .HEX · .XSD

In questa pagina

19k+ estensioni indicizzate
Ultima revisione Sep 10, 2026

Non sei sicuro di cosa sia il tuo file?

Trascina qualsiasi file nel nostro identificatore - leggiamo solo i primi byte per dare un nome al formato.

Identifica un file

Che cos'è il formato di file MJS?

Un file .mjs è codice sorgente JavaScript che Node.js carica come modulo ECMAScript (ESM). L'estensione è un segnale: qualsiasi file che termina in .mjs viene trattato come un modulo ES, utilizzando le istruzioni import ed export, anche quando il package.json del progetto non specifica nulla sul tipo di modulo.

Node.js ha aggiunto l'estensione nella versione 8.5.0 (2017), inizialmente dietro il flag --experimental-modules, e l'ha resa stabile nella versione 12. Esiste per tenere separati i due sistemi di moduli. Il vecchio codice Node utilizza CommonJS con require() e module.exports, mentre il codice moderno utilizza ESM. Un semplice file .js è CommonJS per impostazione predefinita, quindi .mjs offre un modo univoco per optare per i moduli. L'estensione corrispondente .cjs forza CommonJS nella direzione opposta.

Il codice in un file .mjs viene eseguito automaticamente in «strict mode» e può utilizzare await a livello superiore e l'oggetto import.meta, nessuno dei quali funziona in CommonJS. Bundler come webpack, Rollup e Vite leggono e scrivono file .mjs.

Sicurezza e incolumità

RISCHIO: MEDIUM

An .mjs file is executable JavaScript. Running one with node executes whatever code it contains, so an untrusted .mjs file can perform harmful actions such as reading files or making network requests. Opening it in a text editor is safe; only run .mjs files from sources you trust, and review the code first.

Dettagli del formato

in sintesi
NOME COMPLETONode.js ES Module Fileanche noto come Module JavaScript file, ES Module file
SVILUPPATORENode.js Foundation / OpenJS Foundation (Ecma International for ECMAScript)dal 2017 (Node.js v8.5.0)
TIPO MIMEtext/javascript
TIPOPlain-text JavaScript source code
STANDARDAperto · royalty-free
Questa estensione è usata anche da…
  • Generic minified JavaScript module - Some build tools emit .mjs to mark a bundled or minified ES module output rather than a hand-written source file.

Programmi che aprono file MJS

Windows5 apps
Sublime Text A pagamento Open the file for fast editing; JavaScript syntax highlighting applies to .mjs.
Notepad Open-source Open the .mjs file to view and edit the raw source with lightweight syntax highlighting.
Visual Studio Code Gratuito Open the .mjs file to edit it with ESM-aware syntax highlighting, IntelliSense and an integrated terminal for running node.
Node.js runtime Open-source Execute the module from a command prompt with 'node file.mjs'; the runtime loads it as an ES module.
WebStorm A pagamento Open the containing project to get full ESM refactoring, module resolution and debugging.
macOS5 apps
Sublime Text A pagamento Open the .mjs file for quick editing with JavaScript highlighting.
Vim Open-source Edit the file in the terminal with 'vim file.mjs'.
Visual Studio Code Gratuito Open the file to edit with ESM IntelliSense and run it from the built-in terminal.
Node.js runtime Open-source Run 'node file.mjs' in Terminal to execute the module.
WebStorm A pagamento Open the project for module-aware editing, debugging and refactoring of .mjs files.
Linux4 apps
GNU Emacs Open-source Open the .mjs file with js-mode for editing.
Visual Studio Code Gratuito Open the file for ESM-aware editing and run it from the integrated terminal.
Node.js runtime Open-source Execute 'node file.mjs' from a shell to run the module.
Vim / Neovim Open-source Edit the file in the terminal with JavaScript syntax support.
Web2 apps
Modern web browsers Gratuito Load an .mjs file with <script type="module" src="app.mjs"> when the server sends a JavaScript MIME type.
StackBlitz Freemium Open or create .mjs modules in an in-browser Node.js environment and run them instantly.

Dettagli tecnici

specifiche approfondite
EncodingUTF-8 plain text
Byte orderNot applicable (text file, no byte-order dependence; BOM optional but discouraged)
ContainerNone; raw JavaScript source
Typical sizeA few hundred bytes to tens of kilobytes per module
StructureHuman-readable JavaScript source using the ECMAScript module system. Uses static import and export statements, supports top-level await and import.meta, and runs in strict mode by default. Each .mjs file is a module with its own top-level scope; variables are not shared globally.
IntegrityNone built in; integrity is handled externally (npm package hashes, Subresource Integrity on the web, git).
PlatformsWindows, macOS, Linux, BSD, any OS running Node.js or a modern browser
NotesNode.js treats any .mjs file as an ES module regardless of the package.json "type" field, which is the main reason the extension exists. The counterpart .cjs forces CommonJS. Browsers can also load .mjs via <script type="module"> provided the server sends a JavaScript MIME type. Bundlers such as webpack, Rollup, esbuild and Vite read and emit .mjs.
Runs InNode.js runtime and modern web browsers (via script type=module)
Strict ModeAlways enabled; ES modules run in strict mode automatically
Rilasciato2017 (Node.js v8.5.0)
Ultima versioneECMAScript 2015 module system (stabilized in Node.js v12+)
Standard aperto · royalty-free
Specificanodejs.org

Conversioni MJS

Domande e risposte della community

chiesto dagli utenti
Fai una domanda veloce
Ottieni aiuto da persone che lavorano con i file MJS. Sii specifico - includi il tuo sistema e la versione del software.
Nessun account necessario · risposte solitamente entro un giorno

Ancora nessuna domanda - sii il primo a chiedere informazioni sui file MJS.

Domande frequenti

Che cos'è un file .mjs?
È un file sorgente JavaScript che Node.js carica come modulo ECMAScript, utilizzando import ed export invece del require di CommonJS. L'estensione .mjs indica a Node di trattare il file come un modulo ES indipendentemente dalle impostazioni di package.json.
Come si apre un file .mjs?
Puoi aprirlo in qualsiasi editor di codice come Visual Studio Code, Sublime Text o Vim, poiché si tratta di testo semplice. Per eseguirlo, usa il comando «node file.mjs» con Node.js installato.
Qual è la differenza tra .mjs e .js?
Un file .mjs è sempre un modulo ES. Un file .js è CommonJS per impostazione predefinita in Node.js e diventa un modulo ES solo quando il package.json del progetto contiene «"type": "module"». L'estensione .mjs rimuove tale ambiguità.
Qual è la differenza tra .mjs e .cjs?
L'estensione .mjs forza il sistema di moduli ES (import/export), mentre .cjs forza CommonJS (require/module.exports). Consentono di mescolare entrambi i sistemi di moduli in un unico progetto.
I browser possono eseguire i file .mjs?
Sì. Un browser può caricare un file .mjs tramite un tag <script type="module">, ma il server web deve servirlo con un tipo MIME JavaScript come text/javascript.
È sicuro aprire un file .mjs?
Aprirlo in un editor è sicuro perché è solo testo. Eseguirlo significa avviare del codice, quindi esegui i file .mjs solo da fonti attendibili e controllane prima il contenuto.

Riferimenti

1MDN Web Docs - JavaScript modulesdeveloper.mozilla.org
2Node.js Documentation - Modules: ECMAScript modulesnodejs.org

Continua a esplorare

nel database

Migliori estensioni della settimana

1.AQQAQQ Instant Messenger File
2.BINCD/DVD Disc Image (BIN/CUE)
3.PARTPartial Download File
4.MDMarkdown Document
5.RPMSGRestricted Permission Message
6.CRDOWNLOADChrome Partial Download File
7.NOMEDIAAndroid No-Media Marker File
8.PRDXSoftMaker Presentations Document
9.PRO6XProPresenter 6 Bundle File
10.SWFSmall Web Format (Shockwave Flash)

Estensioni correlate

.DOStata Do-File
.MDMarkdown Document
.HEXIntel HEX File
.XSDXML Schema Definition
.MAPSource Map (JavaScript / CSS)
.CONFIGConfiguration File

Strumenti file gratuiti

Un identificatore di file e convertitore di immagini nel browser - tutto viene eseguito sul tuo dispositivo.

Apri la cassetta degli attrezzi

Sfoglia le estensioni dei file A-Z