Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@std/esm

Package Overview
Dependencies
Maintainers
2
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@std/esm

Enable ES modules in Node today!

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.3K
increased by15.52%
Maintainers
2
Weekly downloads
 
Created
Source

@std/esm

This fast, small, zero dependency, package is all you need to enable ES modules in Node 4+ today!

Getting started

  1. Run npm i --save @std/esm in your app or package directory.

  2. Call require("@std/esm") before importing ES modules.

    index.js
    require("@std/esm")
    module.exports = require("./main.mjs").default
    

For package authors with sub modules:

// Have "foo" require only "@std/esm".
require("foo")
// Sub modules work!
const bar = require("foo/bar").default

Enable ESM in the Node CLI by loading @std/esm with the -r option:

node -r @std/esm file.mjs

Enable ESM in the Node REPL by loading @std/esm upon entering:

$ node
> require("@std/esm")
@std/esm enabled
> import path from "path"
undefined
> path.join("hello", "world")
'hello/world'

Standard Features

Defaults are important. The @std/esm loader strives to be as spec-compliant as possible while following Node’s planned built-in behaviors. This means, by default, ESM requires the use of the .mjs extension.

Out of the box @std/esm just works, no configuration necessary, and supports:

Note: You can unlock unambiguous .js use with the "esm":"js" option.

Unlockables

Developers have strong opinions on just about everything. To accommodate, @std/esm allows unlocking extra features with the "@std/esm" or "@std":{"esm":{}} field in your package.json.

Note: All options are off by default.

{
  "@std/esm": {
"await":

A boolean for top-level await in the main ES module

"gz":

A boolean for gzipped module support (i.e. .js.gz, .mjs.gz)

"esm":

A string ESM mode

  • "mjs" files as ESM (default)
  • "all" files as ESM
  • "js" files with import/export/"use module" as ESM
"cjs":

A boolean for CJS features in ESM

 
  }
}

Keywords

FAQs

Package last updated on 10 Aug 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc