{"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,"search_vec":"'0.0.6':25 'actual':17 'among':53 'build':22 'bundl':67 'bundler':57 'cadenc':28 'declar':60 'depend':63 'dirnam':10,33 'document':29 'esbuild':2,6,66 'esbuild-plugin-fileloc':1 'file':19,39 'fileloc':4 'filenam':11 'global':75 'javascript':76 'level':73 'lightweight':61 'like':56 'line':12,49 'locat':74 'metadata':20 'need':70 'node':55 'node-lik':54 'node.js':31 'origin':44 'output':38 'path':46 'plugin':3,7,41 'project':68 'provid':42 'relativedirnam':13 'relativefilenam':15 'releas':27 'replac':9 'resolv':35 'ship':58 'sourc':18,45,72 'source-level':71 'suitabl':64 'time':23 'typescript':59,77 'uniqu':52 'unlik':30 'variabl':50 'version':24","created_at":"2026-04-27T16:58:54.268068+00:00","updated_at":"2026-04-27T16:58:54.268068+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/martonlederer/esbuild-plugin-fileloc","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/esbuild-plugin-fileloc","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-18","next_check":"2026-07-26","install_tag":null}}