Skip to content

Commit 7e75086

Browse files
cjihrigBridgeAR
authored andcommitted
doc: replace createRequireFromPath() references
This commit replaces createRequireFromPath() references with createRequire() references. PR-URL: #27762 Fixes: #27758 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anto Aravinth <[email protected]>
1 parent 55fe340 commit 7e75086

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

doc/api/esm.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ if this behavior is desired.
277277

278278
These 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

283282
An 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
315314
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()`][].
317316

318317
To include an ES module into CommonJS, use [`import()`][].
319318

320319
### <code>import</code> statements
321320

322321
An `import` statement can reference either ES module or CommonJS JavaScript.
323322
Other 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
327326
in 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
369369
module.exports = 'cjs';
370370

371371
// esm.mjs
372-
import { createRequireFromPath as createRequire } from 'module';
372+
import { createRequire } from 'module';
373373
import { fileURLToPath as fromURL } from 'url';
374374

375375
const 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

Comments
 (0)