Socket
Socket
Sign inDemoInstall

mjs-example

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mjs-example

ES module (.mjs) that can be used natively from node 8.5.0+, without transpilers


Version published
Weekly downloads
4
increased by100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

es-module-example-mjs

ES module (.mjs) that can be used natively from node 8.5.0+, without transpilers.

Starting with version 8.5.0, Node.js supports ES modules natively, behind a command line option. Read more at 2ality - Using ES modules natively in Node.js.

How this works

To publish a native ES module, simply define main in package.json to point to a file with the .mjs extension:

{
  "name": "mjs-example",
  "version": "1.0.2",
  "description": "ES native module (.mjs) - requires node 8.5.0+",
  "main": "example.mjs"
}

That's the only change. Your existing transpilation process to support older Node versions will work as before - just make sure to point Babel to the .mjs file(s).

Usage

  1. Install the module:
yarn add mjs-example
# or, npm install mjs-example
  1. Create a test file:
import {hello} from 'mjs-example';
console.log(hello);
  1. Run node (v8.5.0+) with the --experimental-modules flag:
node --experimental-modules mjs-test.mjs

Keywords

FAQs

Last updated on 25 Sep 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc