@@ -277,8 +277,7 @@ if this behavior is desired.
277277
278278These CommonJS variables are not available in ES modules.
279279
280- ` require ` can be imported into an ES module using
281- [ ` module.createRequireFromPath() ` ] [ ] .
280+ ` require ` can be imported into an ES module using [ ` module.createRequire() ` ] [ ] .
282281
283282An equivalent for ` __filename ` and ` __dirname ` is [ ` import.meta.url ` ] [ ] .
284283
@@ -313,15 +312,15 @@ For now, only modules using the `file:` protocol can be loaded.
313312
314313` require ` always treats the files it references as CommonJS. This applies
315314whether ` require ` is used the traditional way within a CommonJS environment, or
316- in an ES module environment using [ ` module.createRequireFromPath () ` ] [ ] .
315+ in an ES module environment using [ ` module.createRequire () ` ] [ ] .
317316
318317To include an ES module into CommonJS, use [ ` import() ` ] [ ] .
319318
320319### <code >import</code > statements
321320
322321An ` import ` statement can reference either ES module or CommonJS JavaScript.
323322Other file types such as JSON and Native modules are not supported. For those,
324- use [ ` module.createRequireFromPath () ` ] [ ] .
323+ use [ ` module.createRequire () ` ] [ ] .
325324
326325` import ` statements are permitted only in ES modules. For similar functionality
327326in CommonJS, see [ ` import() ` ] [ ] .
@@ -362,14 +361,15 @@ to include ES module files from CommonJS code.
362361
363362## CommonJS, JSON, and Native Modules
364363
365- CommonJS, JSON, and Native modules can be used with [ ` module.createRequireFromPath() ` ] [ ] .
364+ CommonJS, JSON, and Native modules can be used with
365+ [ ` module.createRequire() ` ] [ ] .
366366
367367``` js
368368// cjs.js
369369module .exports = ' cjs' ;
370370
371371// esm.mjs
372- import { createRequireFromPath as createRequire } from ' module' ;
372+ import { createRequire } from ' module' ;
373373import { fileURLToPath as fromURL } from ' url' ;
374374
375375const require = createRequire (fromURL (import .meta.url));
@@ -759,7 +759,7 @@ success!
759759[` import ` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
760760[` import ()` ]: #esm_import-expressions
761761[` import .meta .url ` ]: #esm_import_meta
762- [` module .createRequireFromPath ()` ]: modules.html#modules_module_createrequirefrompath_filename
762+ [` module .createRequire ()` ]: modules.html#modules_module_createrequire_filename
763763[CommonJS]: modules.html
764764[ECMAScript-modules implementation]: https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md
765765[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
0 commit comments