@@ -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,42 @@ 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.
346
-
347
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}
351
-
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.
348
+ * Returns: {string} The absolute (` file:` ) URL string for the resolved module.
355
349
356
- > **Caveat** This can result in synchronous file-system operations, which
357
- > can impact performance similarly to ` require.resolve ` .
350
+ [ ` import.meta.resolve ` ][] is a module-relative resolution function scoped to
351
+ each module, returning the URL string .
358
352
359
353
` ` ` js
360
354
const dependencyAsset = import .meta.resolve(' component-lib/asset.css' );
355
+ // file:///app/node_modules/component-lib/asset.css
361
356
` ` `
362
357
363
- ` import .meta.resolve ` also accepts a second argument which is the parent module
364
- from which to resolve:
358
+ All features of the Node.js module resolution are supported. Dependency
359
+ resolutions are subject to the permitted exports resolutions within the package.
365
360
366
361
` ` ` js
367
362
import .meta.resolve(' ./dep' , import.meta.url);
363
+ // file:///app/dep
368
364
` ` `
369
365
366
+ > **Caveat** This can result in synchronous file-system operations, which
367
+ > can impact performance similarly to ` require .resolve ` .
368
+
369
+ Previously, Node.js implemented an asynchonous resolver which also permitted
370
+ a second contextual argument. The implementation has since been updated to be
371
+ synchronous, with the second contextual ` parent` URL still accessible behind the
372
+ ` -- experimental- import -meta-resolve` flag:
373
+
374
+ * ` parent ` {string|URL} An optional absolute parent module URL to resolve from.
375
+
370
376
## Interoperability with CommonJS
371
377
372
378
### ` import` statements
@@ -501,8 +507,8 @@ They can instead be loaded with [`module.createRequire()`][] or
501
507
502
508
Relative resolution can be handled via ` new URL(' ./local' , import.meta.url)` .
503
509
504
- For a complete ` require.resolve` replacement, there is a flagged experimental
505
- [` import.meta.resolve` ][] API.
510
+ For a complete ` require.resolve` replacement, there is the
511
+ [import.meta.resolve][] API.
506
512
507
513
Alternatively ` module.createRequire()` can be used.
508
514
@@ -1672,7 +1678,7 @@ for ESM specifiers is [commonjs-extension-resolution-loader][].
1672
1678
[` data:` URLs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
1673
1679
[` export` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
1674
1680
[` import()` ]: #import-expressions
1675
- [` import.meta.resolve` ]: #importmetaresolvespecifier-parent
1681
+ [` import.meta.resolve` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve
1676
1682
[` import.meta.url` ]: #importmetaurl
1677
1683
[` import` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
1678
1684
[` initialize` ]: #initialize
@@ -1690,6 +1696,7 @@ for ESM specifiers is [commonjs-extension-resolution-loader][].
1690
1696
[cjs-module-lexer]: https://github.com/nodejs/cjs-module-lexer/tree/1.2.2
1691
1697
[commonjs-extension-resolution-loader]: https://github.com/nodejs/loaders-test/tree/main/commonjs-extension-resolution-loader
1692
1698
[custom https loader]: #https-loader
1699
+ [import.meta.resolve]: #importmetaresolvespecifier
1693
1700
[load hook]: #loadurl-context-nextload
1694
1701
[percent-encoded]: url.md#percent-encoding-in-urls
1695
1702
[special scheme]: https://url.spec.whatwg.org/#special-scheme
0 commit comments