Registry / devops / esbuild-plugin-fileloc

esbuild-plugin-fileloc

JSON →
library0.0.6jsnpmunverified

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.

npm install esbuild-plugin-fileloc
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-FIL
E
esbuild-plugin-fileloc
devopsjavascriptv0.0.6
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export (plugin factory)
import filelocPlugin from 'esbuild-plugin-fileloc'
const { default: filelocPlugin } = require('esbuild-plugin-fileloc')
ESM default import is the correct way. CJS require with destructuring of default fails because the package is ESM.
plugin in esbuild config
import filelocPlugin from 'esbuild-plugin-fileloc'; esbuild.build({ plugins: [filelocPlugin()], })
plugins: [filelocPlugin]
The default export is a factory function that must be called (with no arguments) to create the plugin instance.
type reference
/// <reference types="esbuild-plugin-fileloc" />
import 'esbuild-plugin-fileloc/types'
Types are declared as ambient globals via a triple-slash reference. Direct import of types is not supported.

Build a TypeScript file with esbuild and replace __dirname, __filename, __line, etc. with source location values.

import esbuild from 'esbuild'; import filelocPlugin from 'esbuild-plugin-fileloc'; await esbuild.build({ entryPoints: ['src/index.ts'], outfile: 'dist/bundle.js', bundle: true, plugins: [filelocPlugin()], });
Debug
Known issues
gotchaPlugin must be called as a function: filelocPlugin() not filelocPlugin
fix
Use filelocPlugin() in the plugins array.
affects: >=0.0.1
gotchaGlobal variables are only replaced in files processed by esbuild; they are not polyfilled at runtime
fix
Ensure all files that use these globals are bundled by esbuild with the plugin applied.
affects: >=0.0.1
gotchaType declarations require triple-slash reference; importing the module does not augment global scope
fix
Add /// <reference types="esbuild-plugin-fileloc" /> at the top of files that use the globals.
affects: >=0.0.1
deprecatedNo known deprecations as of v0.0.6.
fix
N/A
affects: >=0.0.6
Errors
Common errors & fixes
Cannot find name '__dirname'. Do you need to change your target library?
TypeScript does not know about the global variables without the type reference.
fix
Add /// <reference types="esbuild-plugin-fileloc" /> at the top of your file.
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.
The default export from the module is a function, not a plugin object. The user likely passed filelocPlugin (the function) instead of calling it.
fix
Change plugins: [filelocPlugin] to plugins: [filelocPlugin()].
TypeError: filelocPlugin is not a function
Importing with CommonJS require and destructuring the default export incorrectly.
fix
Use ESM import: import filelocPlugin from 'esbuild-plugin-fileloc'.
Upgrade
Version history
0.0.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
esbuild-plugin-fileloc — npm install esbuild-plugin-fileloc · libregistry