@@ -321,7 +321,7 @@ import { readFileSync } from 'node:fs';
321
321
const buffer = readFileSync (new URL (' ./data.proto' , import .meta.url));
322
322
` ` `
323
323
324
- ### ` import .meta.resolve(specifier[, parent] )`
324
+ ### ` import .meta.resolve(specifier)`
325
325
326
326
<!--
327
327
added:
@@ -336,36 +336,45 @@ changes:
336
336
- v14.18.0
337
337
pr-url: https://github.com/nodejs/node/pull/38587
338
338
description: Add support for WHATWG ` URL` object to ` parentURL` parameter.
339
+ - version:
340
+ - REPLACEME
341
+ pr-url: https://github.com/nodejs/node/pull/49028
342
+ description: Unflag import.meta.resolve, with ` parentURL` parameter still
343
+ flagged.
339
344
-->
340
345
341
- > Stability: 1 - Experimental
342
-
343
- This feature is only available with the ` --experimental-import-meta-resolve`
344
- command flag enabled.
346
+ > Stability: 1.2 - Release candidate
345
347
346
- * ` specifier` {string} The module specifier to resolve relative to ` parent` .
347
- * ` parent ` {string|URL} The absolute parent module URL to resolve from. If none
348
- is specified, the value of ` import.meta.url` is used as the default.
349
- * Returns: {string}
348
+ * ` specifier` {string} The module specifier to resolve relative to the
349
+ current module.
350
+ * Returns: {string} The absolute (` file:` ) URL string for the resolved module.
350
351
351
- Provides a module-relative resolution function scoped to each module, returning
352
- the URL string. In alignment with browser behavior, this now returns
353
- synchronously.
354
-
355
- > **Caveat** This can result in synchronous file-system operations, which
356
- > can impact performance similarly to ` require.resolve` .
352
+ [` import.meta.resolve` ][] is a module-relative resolution function scoped to
353
+ each module, returning the URL string.
357
354
358
355
` ` ` js
359
356
const dependencyAsset = import .meta.resolve(' component-lib/asset.css' );
357
+ // file:///app/node_modules/component-lib/asset.css
360
358
` ` `
361
359
362
- ` import .meta.resolve ` also accepts a second argument which is the parent module
363
- from which to resolve:
360
+ All features of the Node.js module resolution are supported. Dependency
361
+ resolutions are subject to the permitted exports resolutions within the package.
364
362
365
363
` ` ` js
366
364
import .meta.resolve(' ./dep' , import.meta.url);
365
+ // file:///app/dep
367
366
` ` `
368
367
368
+ > **Caveat** This can result in synchronous file-system operations, which
369
+ > can impact performance similarly to ` require .resolve ` .
370
+
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
+
376
+ * ` parent ` {string|URL} An optional absolute parent module URL to resolve from.
377
+
369
378
## Interoperability with CommonJS
370
379
371
380
### ` import` statements
@@ -500,8 +509,8 @@ They can instead be loaded with [`module.createRequire()`][] or
500
509
501
510
Relative resolution can be handled via ` new URL(' ./local' , import.meta.url)` .
502
511
503
- For a complete ` require.resolve` replacement, there is a flagged experimental
504
- [` import.meta.resolve` ][] API.
512
+ For a complete ` require.resolve` replacement, there is the
513
+ [import.meta.resolve][] API.
505
514
506
515
Alternatively ` module.createRequire()` can be used.
507
516
@@ -1705,7 +1714,7 @@ success!
1705
1714
[` data: ` URLs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
1706
1715
[` export ` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
1707
1716
[` import ()` ]: #import-expressions
1708
- [` import .meta .resolve ` ]: #importmetaresolvespecifier-parent
1717
+ [` import .meta .resolve ` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve
1709
1718
[` import .meta .url ` ]: #importmetaurl
1710
1719
[` import ` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
1711
1720
[` initialize ` ]: #initialize
@@ -1722,6 +1731,7 @@ success!
1722
1731
[` util .TextDecoder ` ]: util.md#class-utiltextdecoder
1723
1732
[cjs-module-lexer]: https://github.com/nodejs/cjs-module-lexer/tree/1.2.2
1724
1733
[custom https loader]: #https-loader
1734
+ [import.meta.resolve]: #importmetaresolvespecifier
1725
1735
[load hook]: #loadurl-context-nextload
1726
1736
[percent-encoded]: url.md#percent-encoding-in-urls
1727
1737
[special scheme]: https://url.spec.whatwg.org/#special-scheme
0 commit comments