The import.meta object is a way for a module to access information about itself. It's part of the JavaScript language, but its contents are not standardized. Each "host" (browser, runtime, etc) is free to implement any properties it wishes on the import.meta object.

Bun implements the following properties.

import.meta.dir;   // => "/path/to/project"
import.meta.file;  // => "file.ts"
import.meta.path;  // => "/path/to/project/file.ts"
import.meta.url;   // => "file:///path/to/project/file.ts"

import.meta.main;  // `true` if this file is directly executed by `bun run`
                   // `false` otherwise

import.meta.resolve("zod"); // => "file:///path/to/project/node_modules/zod/index.js"
import.meta.dirAbsolute path to the directory containing the current file, e.g. /path/to/project. Equivalent to __dirname in CommonJS modules (and Node.js)
import.meta.dirnameAn alias to import.meta.dir, for Node.js compatibility
import.meta.envAn alias to process.env.
import.meta.fileThe name of the current file, e.g. index.tsx
import.meta.pathAbsolute path to the current file, e.g. /path/to/project/index.ts. Equivalent to __filename in CommonJS modules (and Node.js)
import.meta.filenameAn alias to import.meta.path, for Node.js compatibility
import.meta.mainIndicates whether the current file is the entrypoint to the current bun process. Is the file being directly executed by bun run or is it being imported?


Resolve a module specifier (e.g. "zod" or "./file.tsx") to a url. Equivalent to import.meta.resolve in browsers

// => "file:///path/to/project/node_modules/zod/index.ts"
import.meta.urlA string url to the current file, e.g. file:///path/to/project/index.ts. Equivalent to import.meta.url in browsers