The directory name of the current module.
This is the same as the ``path.dirname()of the
import.meta.filename`.
Caveat: only present on
file:
modules.
The full absolute path and filename of the current module, with symlinks resolved.
This is the same as the url.fileURLToPath()
of the import.meta.url
.
Caveat only local modules support this property. Modules not using the
file:
protocol will not provide it.
The absolute file:
URL of the module.
This is defined exactly the same as it is in browsers providing the URL of the current module file.
This enables useful patterns such as relative file loading:
import { readFileSync } from 'node:fs';
const buffer = readFileSync(new URL('./data.proto', import.meta.url));
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:
require.resolve
.The module specifier to resolve relative to the current module.
Optional
parent: string | URLAn optional absolute parent module URL to resolve from.
Default: import.meta.url
The absolute URL string that the specifier would resolve to.
The type of
import.meta
.If you need to declare that a given property exists on
import.meta
, this type may be augmented via interface merging.