Skip to content

Commit c20fdb4

Browse files
aduh95targos
authored andcommitted
doc: edit import.meta.resolve documentation
PR-URL: #49247 Backport-PR-URL: #50669 Refs: #49028 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Guy Bedford <[email protected]>
1 parent 1ac389e commit c20fdb4

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
@@ -328,6 +328,9 @@ added:
328328
- v13.9.0
329329
- v12.16.2
330330
changes:
331+
- version: REPLACEME
332+
pr-url: https://github.com/nodejs/node/pull/49028
333+
description: No longer behind the `--experimental-import-meta-resolve` flag.
331334
- version: REPLACEME
332335
pr-url: https://github.com/nodejs/node/pull/44710
333336
description: This API now returns a string synchronously instead of a Promise.
@@ -347,36 +350,35 @@ changes:
347350
348351
* `specifier` {string} The module specifier to resolve relative to the
349352
current module.
350-
* Returns: {string} The absolute (`file:`) URL string for the resolved module.
353+
* Returns: {string} The absolute URL string that the specifier would resolve to.
351354
352355
[`import.meta.resolve`][] is a module-relative resolution function scoped to
353356
each module, returning the URL string.
354357
355358
```js
356359
const dependencyAsset = import.meta.resolve('component-lib/asset.css');
357360
// file:///app/node_modules/component-lib/asset.css
361+
import.meta.resolve('./dep.js');
362+
// file:///app/dep.js
358363
```
359364
360365
All features of the Node.js module resolution are supported. Dependency
361366
resolutions are subject to the permitted exports resolutions within the package.
362367
363-
```js
364-
import.meta.resolve('./dep', import.meta.url);
365-
// file:///app/dep
366-
```
368+
**Caveats**:
367369
368-
> **Caveat** This can result in synchronous file-system operations, which
369-
> can impact performance similarly to `require.resolve`.
370+
* This can result in synchronous file-system operations, which
371+
can impact performance similarly to `require.resolve`.
372+
* This feature is not available within custom loaders (it would
373+
create a deadlock).
370374
371-
Previously, Node.js implemented an asynchronous resolver which also permitted
372-
a second contextual argument. The implementation has since been updated to be
373-
synchronous, with the second contextual `parent` argument still accessible
374-
behind the `--experimental-import-meta-resolve` flag:
375+
**Non-standard API**:
375376
376-
* `parent` {string|URL} An optional absolute parent module URL to resolve from.
377+
When using the `--experimental-import-meta-resolve` flag, that function accepts
378+
a second argument:
377379
378-
> **Caveat** This feature is not available within module customization hooks (it
379-
> would create a deadlock).
380+
* `parent` {string|URL} An optional absolute parent module URL to resolve from.
381+
**Default:** `import.meta.url`
380382
381383
## Interoperability with CommonJS
382384

0 commit comments

Comments
 (0)