resolve

abstract fun resolve(specifier: String): String(source)
abstract fun resolve(specifier: String, parent: String = definedExternally): String(source)
abstract fun resolve(specifier: String, parent: ERROR CLASS: Symbol not found for URL = definedExternally): String(source)

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).

Since

v13.9.0, v12.16.0

Parameters

specifier

The module specifier to resolve relative to the current module.

parent

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