Skip to content

Commit 25c8a13

Browse files
GeoffreyBoothMylesBorins
authored andcommitted
doc: createRequire can take import.meta.url directly
PR-URL: #30495 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com>
1 parent 45e9c31 commit 25c8a13

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

doc/api/esm.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -540,16 +540,15 @@ CommonJS, JSON, and Native modules can be used with
540540
[`module.createRequire()`][].
541541
542542
```js
543-
// cjs.js
543+
// cjs.cjs
544544
module.exports = 'cjs';
545545

546546
// esm.mjs
547547
import { createRequire } from 'module';
548-
import { fileURLToPath as fromURL } from 'url';
549548

550-
const require = createRequire(fromURL(import.meta.url));
549+
const require = createRequire(import.meta.url);
551550

552-
const cjs = require('./cjs');
551+
const cjs = require('./cjs.cjs');
553552
cjs === 'cjs'; // true
554553
```
555554

0 commit comments

Comments
 (0)