-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
doc: clarify module system selection #41383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
1b1159a
dd7140f
97515fd
c19d161
ce3edd0
be6f791
e9c0b15
4c697b7
2cea6a8
21b45bf
93d6a23
fe05b72
5de6698
b08ec87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Command-line options | ||
| # Command-line API | ||
|
|
||
| <!--introduced_in=v5.9.1--> | ||
|
|
||
|
|
@@ -11,16 +11,42 @@ To view this documentation as a manual page in a terminal, run `man node`. | |
|
|
||
| ## Synopsis | ||
|
|
||
| `node [options] [V8 options] [script.js | -e "script" | -] [--] [arguments]` | ||
| `node [options] [V8 options] [<program-entry-point> | -e "script" | -] [--] [arguments]` | ||
|
|
||
| `node inspect [script.js | -e "script" | <host>:<port>] …` | ||
| `node inspect [<program-entry-point> | -e "script" | <host>:<port>] …` | ||
|
|
||
| `node --v8-options` | ||
|
|
||
| Execute without arguments to start the [REPL][]. | ||
|
|
||
| For more info about `node inspect`, see the [debugger][] documentation. | ||
|
|
||
| ## Program entry point | ||
|
|
||
| The program entry point is a specifier-like string. If the string is not an | ||
| absolute path, it's resolved as a relative path from the current working | ||
| directory. That path is then resolved by [CommonJS][] module loader. If no | ||
| corresponding file is found, an error is thrown. | ||
|
|
||
| If a file is found, its path will be passed to the [ECMAScript module loader][] | ||
| under any of the following conditions: | ||
|
|
||
| * The file has an `.mjs` extension. | ||
| * The file nearest parent `package.json` file | ||
| contains a top-level [`"type"`][] field with a value of `"module"`. | ||
| * If the program was started with a command-line flag that forces the entry | ||
| point to be loaded with ECMAScript module loader. | ||
|
||
|
|
||
| Otherwise, the file is loaded using the CommonJS module loader. See | ||
| [File modules][] for more details. | ||
|
|
||
| ### ECMAScript modules loader entry point caveat | ||
|
|
||
| When loading [ECMAScript module loader][] loads the program entry point, the `node` | ||
| command will only accept as input only files with `.js`, `.mjs`, or `.cjs` | ||
| extensions; and with `.wasm` extensions when | ||
| [`--experimental-wasm-modules`][] is enabled. | ||
|
|
||
| ## Options | ||
|
|
||
| <!-- YAML | ||
|
|
@@ -277,8 +303,8 @@ Enable experimental JSON support for the ES Module loader. | |
| added: v9.0.0 | ||
| --> | ||
|
|
||
| Specify the `module` of a custom experimental [ECMAScript Module loader][]. | ||
| `module` may be either a path to a file, or an ECMAScript Module name. | ||
| Specify the `module` of a custom experimental [ECMAScript module loader][]. | ||
| `module` may be any string accepted as an [`import` specifier][]. | ||
|
|
||
| ### `--experimental-policy` | ||
|
|
||
|
|
@@ -1928,15 +1954,19 @@ $ node --max-old-space-size=1536 index.js | |
| ``` | ||
|
|
||
| [Chrome DevTools Protocol]: https://chromedevtools.github.io/devtools-protocol/ | ||
| [ECMAScript Module loader]: esm.md#loaders | ||
| [CommonJS]: modules.md | ||
| [ECMAScript module loader]: esm.md#loaders | ||
| [File modules]: modules.md#file-modules | ||
| [OSSL_PROVIDER-legacy]: https://www.openssl.org/docs/man3.0/man7/OSSL_PROVIDER-legacy.html | ||
| [REPL]: repl.md | ||
| [ScriptCoverage]: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ScriptCoverage | ||
| [Source Map]: https://sourcemaps.info/spec.html | ||
| [Subresource Integrity]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity | ||
| [V8 JavaScript code coverage]: https://v8project.blogspot.com/2017/12/javascript-code-coverage.html | ||
| [`"type"`]: packages.md#type | ||
| [`--cpu-prof-dir`]: #--cpu-prof-dir | ||
| [`--diagnostic-dir`]: #--diagnostic-dirdirectory | ||
| [`--experimental-wasm-modules`]: #--experimental-wasm-modules | ||
| [`--heap-prof-dir`]: #--heap-prof-dir | ||
| [`--openssl-config`]: #--openssl-configfile | ||
| [`--redirect-warnings`]: #--redirect-warningsfile | ||
|
|
@@ -1949,6 +1979,7 @@ $ node --max-old-space-size=1536 index.js | |
| [`dns.lookup()`]: dns.md#dnslookuphostname-options-callback | ||
| [`dns.setDefaultResultOrder()`]: dns.md#dnssetdefaultresultorderorder | ||
| [`dnsPromises.lookup()`]: dns.md#dnspromiseslookuphostname-options | ||
| [`import` specifier]: esm.md#import-specifiers | ||
| [`process.setUncaughtExceptionCaptureCallback()`]: process.md#processsetuncaughtexceptioncapturecallbackfn | ||
| [`tls.DEFAULT_MAX_VERSION`]: tls.md#tlsdefault_max_version | ||
| [`tls.DEFAULT_MIN_VERSION`]: tls.md#tlsdefault_min_version | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -94,12 +94,12 @@ provides interoperability between them and its original module format, | |||||
|
|
||||||
| <!-- type=misc --> | ||||||
|
|
||||||
| Node.js treats JavaScript code as CommonJS modules by default. | ||||||
| Authors can tell Node.js to treat JavaScript code as ECMAScript modules | ||||||
| Node.js has two module systems: [CommonJS][] modules and ECMAScript modules. | ||||||
|
|
||||||
| Authors can tell Node.js to use the ECMAScript modules loader | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I just don’t think the docs should have any references to “the CommonJS modules loader” or the “ECMAScript modules loader”—no average user knows what those are. There’s just Node, and how it interprets source code.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK but using the ES module loader has more effect than on simply JS code (it no longer accepts
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add those other implications here, then. Most people reading these docs wouldn't know about those nuances just because the loader is mentioned.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tried to address that in ce3edd0, PTAL. |
||||||
| via the `.mjs` file extension, the `package.json` [`"type"`][] field, or the | ||||||
aduh95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| `--input-type` flag. See | ||||||
| [Modules: Packages](packages.md#determining-module-system) for more | ||||||
| details. | ||||||
| [`--input-type`][] flag. Outside of those cases, Node.js will use the CommonJS | ||||||
| module loader. See [Determining module system][] for more details. | ||||||
aduh95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| <!-- Anchors to make sure old links find a target --> | ||||||
|
|
||||||
|
|
@@ -1425,6 +1425,7 @@ success! | |||||
| [CommonJS]: modules.md | ||||||
| [Conditional exports]: packages.md#conditional-exports | ||||||
| [Core modules]: modules.md#core-modules | ||||||
| [Determining module system]: packages.md#determining-module-system | ||||||
| [Dynamic `import()`]: https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports | ||||||
| [ECMAScript Top-Level `await` proposal]: https://github.com/tc39/proposal-top-level-await/ | ||||||
| [ES Module Integration Proposal for WebAssembly]: https://github.com/webassembly/esm-integration | ||||||
|
|
@@ -1437,6 +1438,7 @@ success! | |||||
| [WHATWG JSON modules specification]: https://html.spec.whatwg.org/#creating-a-json-module-script | ||||||
| [`"exports"`]: packages.md#exports | ||||||
| [`"type"`]: packages.md#type | ||||||
| [`--input-type`]: cli.md#--input-typetype | ||||||
| [`ArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer | ||||||
| [`SharedArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer | ||||||
| [`TypedArray`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "doc/api/synopsis.md": { | ||
| "command line options": "cli.html#command-line-options", | ||
| "command line options": "cli.html#options", | ||
| "web server": "http.html" | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.