Skip to content

Commit 79126fc

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 f61882b commit 79126fc

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
@@ -848,16 +848,15 @@ CommonJS, JSON, and Native modules can be used with
848848
[`module.createRequire()`][].
849849

850850
```js
851-
// cjs.js
851+
// cjs.cjs
852852
module.exports = 'cjs';
853853
854854
// esm.mjs
855855
import { createRequire } from 'module';
856-
import { fileURLToPath as fromURL } from 'url';
857856
858-
const require = createRequire(fromURL(import.meta.url));
857+
const require = createRequire(import.meta.url);
859858
860-
const cjs = require('./cjs');
859+
const cjs = require('./cjs.cjs');
861860
cjs === 'cjs'; // true
862861
```
863862

0 commit comments

Comments
 (0)