Mresolve
Bun

method

ImportMeta.resolve

specifier: string
): string;
specifier: string,
parent?: string | URL
): string;

import.meta.resolve is a module-relative resolution function scoped to each module, returning the URL string.

const dependencyAsset = import.meta.resolve('component-lib/asset.css');
// file:///app/node_modules/component-lib/asset.css
import.meta.resolve('./dep.js');
// file:///app/dep.js

All features of the Node.js module resolution are supported. Dependency resolutions are subject to the permitted exports resolutions within the package.

Caveats:

  • This can result in synchronous file-system operations, which can impact performance similarly to require.resolve.
  • This feature is not available within custom loaders (it would create a deadlock).
@param specifier

The module specifier to resolve relative to the current module.

@param parent

An optional absolute parent module URL to resolve from. Default: import.meta.url

@returns

The absolute URL string that the specifier would resolve to.