Jump to content
alt:V Multiplayer Forum
Sign in to follow this  
Roms1383

Is using .mjs mandatory

Recommended Posts

Hi everybody,

I'm just wondering : is this required to code using .mjs extension or we can use classic .js files ?

Also, which state of JavaScript is used ? Can we use ES6 for example ?

Thanks in advance :)

Share this post


Link to post
Share on other sites

As far as I know using ES6 is recommended. So .mjs is not mandatory, no. ūüôā

Share this post


Link to post
Share on other sites

I actually believe that, as long as you use the nodejs module, the .mjs extension is required to run at all.
As I understand .mjs is effectively .js for node... 

Share this post


Link to post
Share on other sites
Posted (edited)

Since alt:V¬†updated node.js to v12.x it is not needed to use the .mjs extension to write es6 modules anymore cause node will understand them natively. You just need to add¬†"type": "module" to your package.json. Your files will then handled as ES¬†modules. And btw:¬†.mjs != .js. These extensions are changing¬†actually¬†the way the files are handled by the interpreters. You can keep in mind that ES¬†modules are able to understand commonJS modules but¬† commonJS won¬īt understand ES¬†modules. So if u are doing new Projects use ES Modules because they are powerful, for example: You can use classes, make ur code reusable,¬†webpack will bundle them much faster and maybe, in the future, browser will load them automatically as modules without using the type: "module"¬†attribute. This will be pretty much the case cause¬†Node.js and JS-Foundation have¬†been merged to OpenJS Foundation this year.¬† To find out more about the es6 features and the .mjs/.js comparison i recommend having a look inside this:

 http://es6-features.org/#Constants

 https://medium.com/passpill-project/files-with-mjs-extension-for-javascript-modules-ced195d7c84a

Edited by t4styy

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×
×
  • Create New...