Skip to content

Commit e11c7b7

Browse files
authored
doc: edit import.meta.resolve documentation
PR-URL: #49247 Refs: #49028 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Guy Bedford <[email protected]>
1 parent 7f001c2 commit e11c7b7

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

doc/api/esm.md

+16-14
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ added:
329329
- v13.9.0
330330
- v12.16.2
331331
changes:
332+
- version: 20.6.0
333+
pr-url: https://github.com/nodejs/node/pull/49028
334+
description: No longer behind the `--experimental-import-meta-resolve` flag.
332335
- version: v20.0.0
333336
pr-url: https://github.com/nodejs/node/pull/44710
334337
description: This API now returns a string synchronously instead of a Promise.
@@ -348,36 +351,35 @@ changes:
348351
349352
* `specifier` {string} The module specifier to resolve relative to the
350353
current module.
351-
* Returns: {string} The absolute (`file:`) URL string for the resolved module.
354+
* Returns: {string} The absolute URL string that the specifier would resolve to.
352355
353356
[`import.meta.resolve`][] is a module-relative resolution function scoped to
354357
each module, returning the URL string.
355358
356359
```js
357360
const dependencyAsset = import.meta.resolve('component-lib/asset.css');
358361
// file:///app/node_modules/component-lib/asset.css
362+
import.meta.resolve('./dep.js');
363+
// file:///app/dep.js
359364
```
360365
361366
All features of the Node.js module resolution are supported. Dependency
362367
resolutions are subject to the permitted exports resolutions within the package.
363368
364-
```js
365-
import.meta.resolve('./dep', import.meta.url);
366-
// file:///app/dep
367-
```
369+
**Caveats**:
368370
369-
> **Caveat** This can result in synchronous file-system operations, which
370-
> can impact performance similarly to `require.resolve`.
371+
* This can result in synchronous file-system operations, which
372+
can impact performance similarly to `require.resolve`.
373+
* This feature is not available within custom loaders (it would
374+
create a deadlock).
371375
372-
Previously, Node.js implemented an asynchronous resolver which also permitted
373-
a second contextual argument. The implementation has since been updated to be
374-
synchronous, with the second contextual `parent` argument still accessible
375-
behind the `--experimental-import-meta-resolve` flag:
376+
**Non-standard API**:
376377
377-
* `parent` {string|URL} An optional absolute parent module URL to resolve from.
378+
When using the `--experimental-import-meta-resolve` flag, that function accepts
379+
a second argument:
378380
379-
> **Caveat** This feature is not available within module customization hooks (it
380-
> would create a deadlock).
381+
* `parent` {string|URL} An optional absolute parent module URL to resolve from.
382+
**Default:** `import.meta.url`
381383
382384
## Interoperability with CommonJS
383385

0 commit comments

Comments
 (0)