{"id":21234,"library":"esbuild-plugin-alias","title":"esbuild-plugin-alias","description":"esbuild plugin for creating path aliases, allowing dynamic resolution of import paths based on conditions like environment variables. Version 0.2.1 is the current stable release. The plugin requires absolute file paths for aliases. It is a lightweight alternative to using esbuild's built-in `alias` or custom onResolve plugins, specifically designed for conditional aliasing. It ships TypeScript definitions and is published on npm.","status":"active","version":"0.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/igoradamenko/esbuild-plugin-alias","tags":["javascript","esbuild","alias","plugin","typescript"],"install":[{"cmd":"npm install esbuild-plugin-alias","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-alias","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-alias","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for esbuild plugin API","package":"esbuild","optional":false}],"imports":[{"note":"The package exports a default function, not a named export. In ESM, import default; in CJS, require returns the function directly.","wrong":"const { alias } = require('esbuild-plugin-alias')","symbol":"default","correct":"import alias from 'esbuild-plugin-alias'"},{"note":"Do not destructure the require result. The module.exports is a single function.","wrong":"const { alias } = require('esbuild-plugin-alias')","symbol":"alias (CommonJS)","correct":"const alias = require('esbuild-plugin-alias')"},{"note":"TypeScript types are included, but the export is default. Named import will result in undefined.","wrong":"import { alias } from 'esbuild-plugin-alias'","symbol":"alias (TypeScript)","correct":"import alias from 'esbuild-plugin-alias'"}],"quickstart":{"code":"import alias from 'esbuild-plugin-alias';\nimport esbuild from 'esbuild';\nimport path from 'path';\n\nawait esbuild.build({\n  entryPoints: ['src/app.js'],\n  bundle: true,\n  outfile: 'dist/out.js',\n  plugins: [\n    alias({\n      'settings.env': path.resolve(__dirname, 'src', `settings.${process.env.NODE_ENV ?? 'dev'}.js`),\n    }),\n  ],\n});","lang":"typescript","description":"Creates an alias for 'settings.env' resolving to a path that depends on the NODE_ENV environment variable."},"warnings":[{"fix":"Use path.resolve() or require.resolve() to convert relative paths to absolute.","message":"Alias values must be absolute file paths; relative paths will fail silently or resolve incorrectly.","severity":"breaking","affected_versions":"all"},{"fix":"Use path.resolve(__dirname, relativePath) to generate absolute path.","message":"The plugin does not resolve relative paths starting with './' or '../'; they must be converted to absolute.","severity":"gotcha","affected_versions":"all"},{"fix":"N/A","message":"No breaking changes reported; all versions are stable.","severity":"deprecated","affected_versions":"none"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use path.resolve() to convert the value to an absolute path.","cause":"Alias value is a relative path instead of absolute.","error":"Error: Could not resolve 'settings.env'"},{"fix":"Use default import: import alias from 'esbuild-plugin-alias' or const alias = require('esbuild-plugin-alias').","cause":"Named import { alias } when the package exports a default function.","error":"TypeError: alias is not a function"},{"fix":"Use import.meta.url with fileURLToPath or use path.dirname(new URL(import.meta.url).pathname).","cause":"Using CommonJS-only __dirname in ESM context.","error":"ReferenceError: __dirname is not defined in ES module scope"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}