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