From d370d126c3a2ad302cd15ff8063631983d1b4610 Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Thu, 25 Apr 2019 17:32:04 -0400 Subject: module: throw on require('./path.mjs'); MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is an extremely important part of the ESM implementation that should have been unflagged as a breaking change in v12.0.0 to allow us to unflag ESM in Node.js 12.x before LTS. Assuming we can get consensus on this behavior I would argue that this Semver-Major behavior change could be viewed as a Semver-Patch fix in v12.0.1 PR-URL: https://github.com/nodejs/node/pull/27417 Reviewed-By: Colin Ihrig Reviewed-By: Gus Caplan Reviewed-By: Michaël Zasso Reviewed-By: Rod Vagg Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum Reviewed-By: Jan Krems Reviewed-By: Rich Trott Reviewed-By: Ujjwal Sharma Reviewed-By: Ruben Bridgewater Reviewed-By: Tobias Nießen Reviewed-By: Sakthipriyan Vairamani --- doc/api/modules.md | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'doc/api/modules.md') diff --git a/doc/api/modules.md b/doc/api/modules.md index 4acead178e..ca469d635e 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -132,6 +132,13 @@ variable. Since the module lookups using `node_modules` folders are all relative, and based on the real path of the files making the calls to `require()`, the packages themselves can be anywhere. +## Addenda: The .mjs extension + +It is not possible to `require()` files that have the `.mjs` extension. +Attempting to do so will throw [an error][]. The `.mjs` extension is +reserved for [ECMAScript Modules][] which cannot be loaded via `require()`. +See [ECMAScript Modules][] for more details. + ## All Together... @@ -950,6 +957,8 @@ requireUtil('./some-tool'); [`createRequire()`]: #modules_module_createrequire_filename [`module` object]: #modules_the_module_object [`path.dirname()`]: path.html#path_path_dirname_path +[ECMAScript Modules]: esm.html +[an error]: errors.html#errors_err_require_esm [exports shortcut]: #modules_exports_shortcut [module resolution]: #modules_all_together [module wrapper]: #modules_the_module_wrapper -- cgit v1.2.3