@@ -322,7 +322,7 @@ import { readFileSync } from 'node:fs';
322322const buffer = readFileSync (new URL (' ./data.proto' , import .meta.url));
323323` ` `
324324
325- ### ` import .meta.resolve(specifier[, parent] )`
325+ ### ` import .meta.resolve(specifier)`
326326
327327<!--
328328added:
@@ -337,36 +337,45 @@ changes:
337337 - v14.18.0
338338 pr-url: https://github.com/nodejs/node/pull/38587
339339 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.
340345-->
341346
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
346348
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.
351352
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.
358355
359356` ` ` js
360357const dependencyAsset = import .meta.resolve(' component-lib/asset.css' );
358+ // file:///app/node_modules/component-lib/asset.css
361359` ` `
362360
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.
365363
366364` ` ` js
367365import .meta.resolve(' ./dep' , import.meta.url);
366+ // file:///app/dep
368367` ` `
369368
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+
370379## Interoperability with CommonJS
371380
372381### ` import` statements
@@ -501,8 +510,8 @@ They can instead be loaded with [`module.createRequire()`][] or
501510
502511Relative resolution can be handled via ` new URL(' ./local' , import.meta.url)` .
503512
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.
506515
507516Alternatively ` module.createRequire()` can be used.
508517
@@ -1698,7 +1707,7 @@ for ESM specifiers is [commonjs-extension-resolution-loader][].
16981707[` data:` URLs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
16991708[` export` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
17001709[` 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
17021711[` import.meta.url` ]: #importmetaurl
17031712[` import` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
17041713[` initialize` ]: #initialize
@@ -1716,6 +1725,7 @@ for ESM specifiers is [commonjs-extension-resolution-loader][].
17161725[cjs-module-lexer]: https://github.com/nodejs/cjs-module-lexer/tree/1.2.2
17171726[commonjs-extension-resolution-loader]: https://github.com/nodejs/loaders-test/tree/main/commonjs-extension-resolution-loader
17181727[custom https loader]: #https-loader
1728+ [import.meta.resolve]: #importmetaresolvespecifier
17191729[load hook]: #loadurl-context-nextload
17201730[percent-encoded]: url.md#percent-encoding-in-urls
17211731[special scheme]: https://url.spec.whatwg.org/#special-scheme
0 commit comments