-
Notifications
You must be signed in to change notification settings - Fork 28.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: support require()ing synchronous ESM graphs
This patch adds `require()` support for synchronous ESM graphs under the flag --experimental-require-module. This is based on the the following design aspect of ESM: - The resolution can be synchronous (up to the host) - The evaluation of a synchronous graph (without top-level await) is also synchronous, and, by the time the module graph is instantiated (before evaluation starts), this is is already known. When --experimental-require-module is enabled, and require() resolves to an ES module, if the module is fully synchronous (contains no top-level await), the `require()` call returns the module name space object. Otherwise, Node.js throws an error without executing the module. If `--print-required-tla` is passed, Node.js will evaluate the module, try to locate the top-level awaits, and print their location to help users fix them. With this option alone, the module being `require()`'d should be explicitly marked as an ES module either using the `"type": "module"` field in `package.json` or the `.mjs` extension. To load implicit ES modules ending with `.js` using automatic syntax-based module type detection, use `--experimental-require-module-with-detection`.
- Loading branch information
1 parent
b209b83
commit a1b3cd4
Showing
37 changed files
with
1,030 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.