Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
This fast, small, zero-dependency package is all you need to enable ES modules in Node 6+ today!
See the release post :book: and video :movie_camera: for all the details.
Run npm i --save @std/esm
in your app or package directory.
There are three ways to enable ESM with @std/esm
.
Enable ESM with a CJS bridge:
index.js
// Provide options as a parameter, environment variable, or rc file.
require = require("@std/esm")(module/*, options*/)
module.exports = require("./main.mjs").default
Enable ESM in the Node CLI with the -r
option:
node -r @std/esm main.mjs
Enable ESM in the Node REPL:
node -r @std/esm
or upon entering:
$ node
> require("@std/esm")
@std/esm enabled
Note: All "cjs"
options are unlocked in the Node REPL.
The @std/esm
loader is as spec-compliant
as possible and follows Node’s ESM rules.
:point_right: This means, by default, ESM requires the use of the .mjs
file
extension.
:unlock: You can unlock ESM with the .js
file extension using
the "js"
ESM mode.
Out of the box @std/esm
just works, no configuration necessary, and supports:
import
/ export
import.meta
import
.mjs
files as ESM--eval
and --print
flagsUnlock features with options specified as one of the following:
"@std/esm"
field in your package.jsonESM_OPTIONS
environment variableCommonly used options may be specified in shorthand form:
"@std/esm":"js"
is shorthand for "@std/esm":{"mode":"js"}
"@std/esm":"cjs"
is shorthand for "@std/esm":{"cjs":true,"mode":"js"}
{ | |||||||||||||||||
"mode": | A string mode:
| ||||||||||||||||
"cjs": | A boolean or object to unlock CJS features in ESM. Unlockable Features
| ||||||||||||||||
"await": | A boolean for top-level | ||||||||||||||||
} |
{ | |
"cache": | A boolean for toggling cache creation or string path of the cache directory. |
"debug": | A boolean for unmasking stack traces. |
"sourceMap": | A boolean for including inline source maps. |
"warnings": | A boolean for logging development parse and runtime warnings. |
} |
@std/esm
before
@babel/register
v7+@std/esm
with the “require” option of
ava
,
mocha
,
nyc
, and
tape
@std/esm
with the --node-arg=-r --node-arg=@std/esm
option of
node-tap
@std/esm
with the --node-args="-r @std/esm"
option of
pm2
@std/esm
with wallaby.js
@std/esm
to load jasmine
"@std/esm":"cjs"
for the --watch
and --watch-extensions
options of
mocha
"@std/esm":"cjs"
for ava
and webpack
"@std/esm":"cjs"
FAQs
Enable ES modules in Node today!
The npm package @std/esm receives a total of 1,757 weekly downloads. As such, @std/esm popularity was classified as popular.
We found that @std/esm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.