@@ -277,8 +277,7 @@ if this behavior is desired.
277
277
278
278
These CommonJS variables are not available in ES modules.
279
279
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() ` ] [ ] .
282
281
283
282
An equivalent for ` __filename ` and ` __dirname ` is [ ` import.meta.url ` ] [ ] .
284
283
@@ -313,15 +312,15 @@ For now, only modules using the `file:` protocol can be loaded.
313
312
314
313
` require ` always treats the files it references as CommonJS. This applies
315
314
whether ` 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 () ` ] [ ] .
317
316
318
317
To include an ES module into CommonJS, use [ ` import() ` ] [ ] .
319
318
320
319
### <code >import</code > statements
321
320
322
321
An ` import ` statement can reference either ES module or CommonJS JavaScript.
323
322
Other file types such as JSON and Native modules are not supported. For those,
324
- use [ ` module.createRequireFromPath () ` ] [ ] .
323
+ use [ ` module.createRequire () ` ] [ ] .
325
324
326
325
` import ` statements are permitted only in ES modules. For similar functionality
327
326
in CommonJS, see [ ` import() ` ] [ ] .
@@ -362,14 +361,15 @@ to include ES module files from CommonJS code.
362
361
363
362
## CommonJS, JSON, and Native Modules
364
363
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() ` ] [ ] .
366
366
367
367
``` js
368
368
// cjs.js
369
369
module .exports = ' cjs' ;
370
370
371
371
// esm.mjs
372
- import { createRequireFromPath as createRequire } from ' module' ;
372
+ import { createRequire } from ' module' ;
373
373
import { fileURLToPath as fromURL } from ' url' ;
374
374
375
375
const require = createRequire (fromURL (import .meta.url));
@@ -759,7 +759,7 @@ success!
759
759
[` import ` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
760
760
[` import ()` ]: #esm_import-expressions
761
761
[` import .meta .url ` ]: #esm_import_meta
762
- [` module .createRequireFromPath ()` ]: modules.html#modules_module_createrequirefrompath_filename
762
+ [` module .createRequire ()` ]: modules.html#modules_module_createrequire_filename
763
763
[CommonJS]: modules.html
764
764
[ECMAScript-modules implementation]: https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md
765
765
[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
0 commit comments