{"id":21250,"library":"esbuild-plugin-fileloc","title":"esbuild-plugin-fileloc","description":"An esbuild plugin that replaces __dirname, __filename, __line, __relativedirname, and __relativefilename with actual source file metadata at build time. Version 0.0.6, no release cadence documented. Unlike Node.js's __dirname (which resolves to the output file), this plugin provides the original source path, and the __line variable is unique among Node-like bundlers. Ships TypeScript declarations. Lightweight, no dependencies. Suitable for esbuild bundling projects that need source-level location globals.","status":"active","version":"0.0.6","language":"javascript","source_language":"en","source_url":"https://github.com/martonlederer/esbuild-plugin-fileloc","tags":["javascript","typescript"],"install":[{"cmd":"npm install esbuild-plugin-fileloc","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-fileloc","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-fileloc","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM default import is the correct way. CJS require with destructuring of default fails because the package is ESM.","wrong":"const { default: filelocPlugin } = require('esbuild-plugin-fileloc')","symbol":"default export (plugin factory)","correct":"import filelocPlugin from 'esbuild-plugin-fileloc'"},{"note":"The default export is a factory function that must be called (with no arguments) to create the plugin instance.","wrong":"plugins: [filelocPlugin]","symbol":"plugin in esbuild config","correct":"import filelocPlugin from 'esbuild-plugin-fileloc';\nesbuild.build({\n  plugins: [filelocPlugin()],\n})"},{"note":"Types are declared as ambient globals via a triple-slash reference. Direct import of types is not supported.","wrong":"import 'esbuild-plugin-fileloc/types'","symbol":"type reference","correct":"/// <reference types=\"esbuild-plugin-fileloc\" />"}],"quickstart":{"code":"import esbuild from 'esbuild';\nimport filelocPlugin from 'esbuild-plugin-fileloc';\n\nawait esbuild.build({\n  entryPoints: ['src/index.ts'],\n  outfile: 'dist/bundle.js',\n  bundle: true,\n  plugins: [filelocPlugin()],\n});","lang":"typescript","description":"Build a TypeScript file with esbuild and replace __dirname, __filename, __line, etc. with source location values."},"warnings":[{"fix":"Use filelocPlugin() in the plugins array.","message":"Plugin must be called as a function: filelocPlugin() not filelocPlugin","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Ensure all files that use these globals are bundled by esbuild with the plugin applied.","message":"Global variables are only replaced in files processed by esbuild; they are not polyfilled at runtime","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Add /// <reference types=\"esbuild-plugin-fileloc\" /> at the top of files that use the globals.","message":"Type declarations require triple-slash reference; importing the module does not augment global scope","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"N/A","message":"No known deprecations as of v0.0.6.","severity":"deprecated","affected_versions":">=0.0.6"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Add /// <reference types=\"esbuild-plugin-fileloc\" /> at the top of your file.","cause":"TypeScript does not know about the global variables without the type reference.","error":"Cannot find name '__dirname'. Do you need to change your target library?"},{"fix":"Change plugins: [filelocPlugin] to plugins: [filelocPlugin()].","cause":"The default export from the module is a function, not a plugin object. The user likely passed filelocPlugin (the function) instead of calling it.","error":"Error: The plugin \"esbuild-plugin-fileloc\" is not a valid esbuild plugin. Expected either a string or an object with a name and setup function."},{"fix":"Use ESM import: import filelocPlugin from 'esbuild-plugin-fileloc'.","cause":"Importing with CommonJS require and destructuring the default export incorrectly.","error":"TypeError: filelocPlugin is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}