{"id":13432182,"url":"https://github.com/standard-things/esm","last_synced_at":"2025-04-08T19:15:16.496Z","repository":{"id":39339067,"uuid":"92424220","full_name":"standard-things/esm","owner":"standard-things","description":"Tomorrow's ECMAScript modules today!","archived":false,"fork":false,"pushed_at":"2024-04-10T19:03:12.000Z","size":10384,"stargazers_count":5272,"open_issues_count":85,"forks_count":147,"subscribers_count":57,"default_branch":"master","last_synced_at":"2024-10-29T10:54:53.591Z","etag":null,"topics":["es6","es6-modules","esm","esmodules","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/standard-things.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-25T16:46:17.000Z","updated_at":"2024-10-24T07:10:57.000Z","dependencies_parsed_at":"2022-07-04T07:04:40.691Z","dependency_job_id":"652b8ce2-edb0-427d-8a6f-f3e1c6aa36bb","html_url":"https://github.com/standard-things/esm","commit_stats":{"total_commits":6360,"total_committers":28,"mean_commits":"227.14285714285714","dds":0.08474842767295598,"last_synced_commit":"511d672ae13e8bee13ba19bd7fdc2a3206c9d7d7"},"previous_names":[],"tags_count":189,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/standard-things%2Fesm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/standard-things%2Fesm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/standard-things%2Fesm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/standard-things%2Fesm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/standard-things","download_url":"https://codeload.github.com/standard-things/esm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247185343,"owners_count":20897948,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["es6","es6-modules","esm","esmodules","nodejs"],"created_at":"2024-07-31T02:01:09.234Z","updated_at":"2025-04-08T19:15:16.470Z","avatar_url":"https://github.com/standard-things.png","language":"JavaScript","readme":"# esm\n\nThe brilliantly simple, babel-less, bundle-less ECMAScript module loader.\n\n\u003e `esm` is the world’s most advanced ECMAScript module loader.\nThis fast, production ready, zero dependency loader is all you need to support\nECMAScript modules in Node 6+. See the release [post](https://medium.com/web-on-the-edge/tomorrows-es-modules-today-c53d29ac448c)\nand [video](https://www.youtube.com/watch?v=JcZ-FzfDq8A#t=5) for details!\n\nInstall\n---\n\n* __New projects__\n\n  Run `npm init esm` or `yarn create esm`.\n\n  :bulb: Use the `-y` flag to answer “yes” to all prompts.\n\n* __Existing projects__\n\n  Run `npm i esm` or `yarn add esm`.\n\nGetting started\n---\n\nThere are two ways to enable `esm`.\n\n1. Enable `esm` for packages:\n\n   Use `esm` to load the main ES module and export it as CommonJS.\n\n    __index.js__\n    ```js\n    // Set options as a parameter, environment variable, or rc file.\n    require = require(\"esm\")(module/*, options*/)\n    module.exports = require(\"./main.js\")\n    ```\n    __main.js__\n    ```js\n    // ESM syntax is supported.\n    export {}\n    ```\n    :bulb: These files are automagically created with `npm init esm` or `yarn create esm`.\n\n2. Enable `esm` for local runs:\n\n    ```shell\n    node -r esm main.js\n    ```\n    :bulb: Omit the filename to enable `esm` in the REPL.\n\nFeatures\n---\n\n:clap: By default, :100: percent CJS interoperability is enabled so you can get stuff done.\u003cbr\u003e\n:lock: `.mjs` files are limited to basic functionality without support for `esm` options.\n\nOut of the box `esm` just works, no configuration necessary, and supports:\n\n* Passing all applicable [test262](https://github.com/tc39/test262) compliance tests\n* [`import`](https://ponyfoo.com/articles/es6-modules-in-depth#import)/[`export`](https://ponyfoo.com/articles/es6-modules-in-depth#export)\n* [`import.meta`](https://github.com/tc39/proposal-import-meta)\n* [Dynamic `import`](https://github.com/tc39/proposal-dynamic-import)\n* [Live bindings](https://ponyfoo.com/articles/es6-modules-in-depth#bindings-not-values)\n* [File URI scheme](https://en.wikipedia.org/wiki/File_URI_scheme)\n* Node `stdin`, [`--eval`](https://nodejs.org/api/cli.html#cli_e_eval_script), [`--print`](https://nodejs.org/api/cli.html#cli_p_print_script) flags\n* Node [`--check`](https://nodejs.org/api/cli.html#cli_c_check) flag _(Node 10+)_\n\nOptions\n---\n\nSpecify options with one of the following:\n\n* `\"esm\"` field in `package.json`\n* CJS/ESM in an `.esmrc.js`, `.esmrc.cjs`, or `.esmrc.mjs` file\n* [JSON6](https://github.com/d3x0r/json6) in an `.esmrc` or `.esmrc.json` file\n* JSON6 or file path in the `ESM_OPTIONS` environment variable\n* `ESM_DISABLE_CACHE` environment variable\n\n\u003ctable\u003e\n\u003ctr\u003e\n  \u003ctd colspan=\"2\"\u003e\u003ccode\u003e{\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"cjs\":true\u003c/code\u003e\u003c/td\u003e\n  \u003ctd\u003e\n    \u003cp\u003eA boolean or object for toggling CJS features in ESM.\u003c/p\u003e\n    \u003cdetails\u003e\n      \u003csummary\u003eFeatures\u003c/summary\u003e\n      \u003ctable\u003e\n      \u003ctr\u003e\n        \u003ctd colspan=\"2\"\u003e\u003ccode\u003e{\u003c/code\u003e\u003c/td\u003e\n      \u003c/tr\u003e\n      \u003ctr\u003e\n        \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"cache\":true\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003e\n          \u003cp\u003eA boolean for storing ES modules in \u003ccode\u003erequire.cache\u003c/code\u003e.\u003c/p\u003e\n        \u003c/td\u003e\n      \u003c/tr\u003e\n      \u003ctr\u003e\n        \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"esModule\":true\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003e\n          \u003cp\u003eA boolean for \u003ccode\u003e__esModule\u003c/code\u003e interoperability.\u003c/p\u003e\n        \u003c/td\u003e\n      \u003c/tr\u003e\n      \u003ctr\u003e\n        \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"extensions\":true\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003e\n          \u003cp\u003eA boolean for respecting \u003ccode\u003erequire.extensions\u003c/code\u003e in ESM.\u003c/p\u003e\n        \u003c/td\u003e\n      \u003c/tr\u003e\n      \u003ctr\u003e\n        \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"mutableNamespace\":true\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003e\n          \u003cp\u003eA boolean for mutable \u003ca href=\"https://ponyfoo.com/articles/es6-modules-in-depth#import-all-the-things\"\u003enamespace objects\u003c/a\u003e.\u003c/p\u003e\n        \u003c/td\u003e\n      \u003c/tr\u003e\n      \u003ctr\u003e\n        \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"namedExports\":true\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003e\n          \u003cp\u003eA boolean for \u003ca href=\"https://ponyfoo.com/articles/es6-modules-in-depth#importing-named-exports\"\u003eimporting named exports\u003c/a\u003e of CJS modules.\u003c/p\u003e\n        \u003c/td\u003e\n      \u003c/tr\u003e\n      \u003ctr\u003e\n        \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"paths\":true\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003e\n          \u003cp\u003eA boolean for following CJS \u003ca href=\"https://github.com/nodejs/node-eps/blob/master/002-es-modules.md#432-removal-of-non-local-dependencies\"\u003epath rules\u003c/a\u003e in ESM.\u003c/p\u003e\n        \u003c/td\u003e\n      \u003c/tr\u003e\n      \u003ctr\u003e\n        \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"vars\":true\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003e\n          \u003cp\u003eA boolean for \u003ccode\u003e__dirname\u003c/code\u003e, \u003ccode\u003e__filename\u003c/code\u003e, and \u003ccode\u003erequire\u003c/code\u003e in ESM.\u003c/p\u003e\n        \u003c/td\u003e\n      \u003c/tr\u003e\n      \u003ctr\u003e\n        \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"dedefault\":false\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003e\n          \u003cp\u003eA boolean for requiring ES modules without the dangling \u003ccode\u003erequire().default\u003c/code\u003e.\u003c/p\u003e\n        \u003c/td\u003e\n      \u003c/tr\u003e\n      \u003ctr\u003e\n        \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"topLevelReturn\":false\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003e\n          \u003cp\u003eA boolean for top-level \u003ccode\u003ereturn\u003c/code\u003e support.\u003c/p\u003e\n        \u003c/td\u003e\n      \u003c/tr\u003e\n      \u003ctr\u003e\n        \u003ctd colspan=\"2\"\u003e\u003ccode\u003e}\u003c/code\u003e\u003c/td\u003e\n      \u003c/tr\u003e\n      \u003c/table\u003e\n    \u003c/details\u003e\n  \u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"mainFields\":[\"main\"]\u003c/code\u003e\u003c/td\u003e\n  \u003ctd\u003e\n    \u003cp\u003eAn array of fields checked when importing a package.\u003c/p\u003e\n  \u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"mode\":\"auto\"\u003c/code\u003e\u003c/td\u003e\n  \u003ctd\u003e\n    \u003cp\u003eA string mode:\u003c/p\u003e\n    \u003cul\u003e\n      \u003cli\u003e\u003ccode\u003e\"auto\"\u003c/code\u003e detect files with \u003ccode\u003eimport\u003c/code\u003e, \u003ccode\u003eimport.meta\u003c/code\u003e, \u003ccode\u003eexport\u003c/code\u003e,\u003cbr\u003e\u003ca href=\"https://github.com/tc39/proposal-modules-pragma\"\u003e\u003ccode\u003e\"use module\"\u003c/code\u003e\u003c/a\u003e, or \u003ccode\u003e.mjs\u003c/code\u003e as ESM.\u003c/li\u003e\n      \u003cli\u003e\u003ccode\u003e\"all\"\u003c/code\u003e files besides those with \u003ccode\u003e\"use script\"\u003c/code\u003e or \u003ccode\u003e.cjs\u003c/code\u003e are treated as ESM.\u003c/li\u003e\n      \u003cli\u003e\u003ccode\u003e\"strict\"\u003c/code\u003e to treat \u003cstrong\u003eonly\u003c/strong\u003e \u003ccode\u003e.mjs\u003c/code\u003e files as ESM.\u003c/li\u003e\n    \u003c/ul\u003e\n  \u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"await\":false\u003c/code\u003e\u003c/td\u003e\n  \u003ctd\u003e\n    \u003cp\u003eA boolean for \u003ca href=\"https://github.com/tc39/proposal-top-level-await\"\u003etop-level \u003ccode\u003eawait\u003c/code\u003e\u003c/a\u003e in modules without ESM exports. \u003cem\u003e(Node 10+)\u003c/em\u003e\u003c/p\u003e\n  \u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"force\":false\u003c/code\u003e\u003c/td\u003e\n  \u003ctd\u003e\n    \u003cp\u003eA boolean to apply these options to all module loads.\u003c/p\u003e\n  \u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"wasm\":false\u003c/code\u003e\u003c/td\u003e\n  \u003ctd\u003e\n    \u003cp\u003eA boolean for \u003ca href=\"https://nodejs.org/api/globals.html#globals_webassembly\"\u003eWebAssembly\u003c/a\u003e module support. \u003cem\u003e(Node 8+)\u003c/em\u003e\u003c/p\u003e\n  \u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd colspan=\"2\"\u003e\u003ccode\u003e}\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\nDevOpts\n---\n\n\u003ctable\u003e\n\u003ctr\u003e\n  \u003ctd colspan=\"2\"\u003e\u003ccode\u003e{\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"cache\":true\u003c/code\u003e\u003c/td\u003e\n  \u003ctd\u003e\n    \u003cp\u003eA boolean for toggling cache creation or a cache directory path.\u003c/p\u003e\n  \u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"sourceMap\":false\u003c/code\u003e\u003c/td\u003e\n  \u003ctd\u003e\n    \u003cp\u003eA boolean for including inline source maps.\u003c/p\u003e\n  \u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd colspan=\"2\"\u003e\u003ccode\u003e}\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\nTips\n---\n\n### Bundling\n\n* For bundlers like [`browserify`](http://browserify.org/)+[`esmify`](https://github.com/mattdesl/esmify),\n  [`parcel-bundler`](https://parceljs.org/), and [`webpack`](https://webpack.js.org/)\n  add a `\"module\"` field to `package.json` pointing to the main ES module.\n  ```json\n  \"main\": \"index.js\",\n  \"module\": \"main.js\"\n  ```\n\n  :bulb: This is automagically done with `npm init esm` or `yarn create esm`.\n\n### Extensions\n\n* Enable `esm` for [`wallaby.js`](https://wallabyjs.com/) following their\n  [integration example](https://wallabyjs.com/docs/integration/node.html#es-modules).\n\n### Loading\n\n* Load `esm` before loaders/monitors like\n  [`@babel/register`](https://babeljs.io/docs/en/next/babel-register.html),\n  [`newrelic`](https://github.com/newrelic/node-newrelic),\n  [`sqreen`](https://docs.sqreen.io/sqreen-for-nodejs/getting-started-2/), and\n  [`ts-node`](https://github.com/TypeStrong/ts-node#programmatic).\n\n* Load `esm` for [`jasmine`](https://jasmine.github.io/) using the\n  [`\"helpers\"`](https://jasmine.github.io/setup/nodejs.html#configuration)\n  field in `jasmine.json`:\n  ```json\n  \"helpers\": [\n    \"node_modules/esm\"\n  ]\n  ```\n\n* Load `esm` with “node-args\" options of:\u003cbr\u003e\n  - [`pm2`](https://pm2.io/doc/en/runtime/reference/pm2-cli/#pm2-flags): `--node-args=\"-r esm\"`\n\n* Load `esm` with “require” options of\n  [`ava`](https://github.com/avajs/ava/blob/master/docs/recipes/es-modules.md),\n  [`mocha`](https://mochajs.org/#-require-module-r-module),\n  [`nodemon`](https://nodemon.io/),\n  [`nyc`](https://github.com/istanbuljs/nyc#require-additional-modules),\n  [`qunit`](https://github.com/qunitjs/qunit/releases/tag/2.6.0),\n  [`tape`](https://github.com/substack/tape#preloading-modules), and\n  [`webpack`](https://webpack.js.org/api/cli/#config-options).\n\n  :bulb: Builtin `require` cannot sideload `.mjs` files. However, `.js` files\n  can be sideloaded or `.mjs` files may be loaded with dynamic `import`.\n","funding_links":[],"categories":["JavaScript","GIT 仓库"],"sub_categories":["ES Module"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstandard-things%2Fesm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstandard-things%2Fesm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstandard-things%2Fesm/lists"}