Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@nore/esm

nore50ISC2.4.0

Converts ES Modules to CommonJS at runtime

readme

@nore/esm

Allows the use of import and export syntax in node.js.

Under the hood it wraps node's loading mechanism, parses all required files, converting ES Modules syntax to node's syntax (CJS).

Installation

  $ npm install @nore/esm

API

Relative imports to source's path (~/path)

This module also handles relative paths to the project's source folder: ~/path/to/file.js. By default it resolves the ~ to process.cwd(), this can be overwritten by setting the path on ES_SOURCE_PATH (environment variable).

import accounts from "~/services/accounts"

@nore/esm/register

Convert ES Modules to CommonJS on runtime:

// read.js
import { readFile } from 'fs'

export default (path, handler) => {
  readFile(path, 'utf8', handler)
}
// index.js
require("@nore/esm/register");

const read = require("./read.js");

es CLI command

Run ES Modules files:

// passwords.js
import { readFileSync } from 'fs'

console.log(readFileSync('/etc/passwd', 'utf8'))
es passwords.js

License ISC  ·  GitHub @ugin  ·  Twitter @navaru