ReadonlydirAbsolute path to the directory containing the source file.
Does not have a trailing slash
Alias of import.meta.dir. Exists for Node.js compatibility
ReadonlyenvThe environment variables of the process
import.meta.env === process.env
ReadonlyfileFilename of the source file
Alias of import.meta.path. Exists for Node.js compatibility
Hot module replacement APIs. This value is undefined in production and
can be used in an if statement to check if HMR APIs are available
if (import.meta.hot) {
// HMR APIs are available
}
However, this check is usually not needed as Bun will dead-code-eliminate calls to all of the HMR APIs in production builds.
import.meta.hot.data maintains state between module instances during
hot replacement, enabling data transfer from previous to new versions.
When import.meta.hot.data is written to, Bun will mark this module as
capable of self-accepting (equivalent of calling accept()).
Indicate that this module can be replaced simply by re-evaluating the file. After a hot update, importers of this module will be automatically patched.
When import.meta.hot.accept is not used, the page will reload when
the file updates, and a console message shows which files were checked.
Indicate that this module can be replaced by evaluating the new module,
and then calling the callback with the new module. In this mode, the
importers do not get patched. This is to match Vite, which is unable
to patch their import statements. Prefer using import.meta.hot.accept()
without an argument as it usually makes your code easier to understand.
When import.meta.hot.accept is not used, the page will reload when
the file updates, and a console message shows which files were checked.
Indicate that a dependency's module can be accepted. When the dependency is updated, the callback will be called with the new module.
When import.meta.hot.accept is not used, the page will reload when
the file updates, and a console message shows which files were checked.
Indicate that a dependency's module can be accepted. This variant
accepts an array of dependencies, where the callback will receive
the one updated module, and undefined for the rest.
When import.meta.hot.accept is not used, the page will reload when
the file updates, and a console message shows which files were checked.
Attach an on-dispose callback. This is called:
This callback is not called on route navigation or when the browser tab closes.
Returning a promise will delay module replacement until the module is disposed. All dispose callbacks are called in parallel.
Stop listening for an event from the dev server
For compatibility with Vite, event names are also available via vite:* prefix instead of bun:*.
The event to stop listening to
The callback to stop listening to
Listen for an event from the dev server
For compatibility with Vite, event names are also available via vite:* prefix instead of bun:*.
The event to listen to
The callback to call when the event is emitted
Did the current file start the process?
ReadonlypathAbsolute path to the source file
Load a CommonJS module within an ES Module. Bun's transpiler rewrites all
calls to require with import.meta.require when transpiling ES Modules
for the runtime.
Warning: This API is not stable and may change or be removed in the future. Use at your own risk.
file:// url string for the current module.
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.