{"id":21242,"library":"esbuild-plugin-env","title":"esbuild-plugin-env","description":"ESBuild plugin (v1.1.1, maintained) that loads environment variables using dotenv and makes them available via process.env at build time. Key differentiators: automatically sets NODE_ENV based on minify flag, provides PROD/DEV boolean constants, supports custom key prefix (default ESB_), and allows overriding production detection. Ships TypeScript types. Alternative to @jvdx/esbuild-plugin-env or manual define replacements.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/yamitsushi/esbuild-plugin-env","tags":["javascript","ESBuild","esbuild","plugin","typescript"],"install":[{"cmd":"npm install esbuild-plugin-env","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-env","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-env","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"runtime dependency for loading .env files","package":"dotenv","optional":false},{"reason":"peer dependency required to use as plugin","package":"esbuild","optional":false}],"imports":[{"note":"Default export only; named import will result in undefined.","wrong":"import { env } from 'esbuild-plugin-env'","symbol":"env","correct":"import env from 'esbuild-plugin-env'"},{"note":"CJS require returns the default export directly; destructuring breaks.","wrong":"const { env } = require('esbuild-plugin-env')","symbol":"env","correct":"const env = require('esbuild-plugin-env')"},{"note":"Type import only; use `import type` for type-only consumption.","wrong":"import { EnvOptions } from 'esbuild-plugin-env'","symbol":"type EnvOptions","correct":"import type { EnvOptions } from 'esbuild-plugin-env'"}],"quickstart":{"code":"import esbuild from 'esbuild';\nimport env from 'esbuild-plugin-env';\n\nawait esbuild.build({\n  entryPoints: ['./src/index.js'],\n  bundle: true,\n  minify: true,\n  outfile: './dist/bundle.js',\n  plugins: [env()],\n});\n\n// .env file:\n// ESB_API_KEY=abc123\n// In source:\n// console.log(process.env.ESB_API_KEY); // 'abc123'\n// console.log(process.env.PROD); // true\n// console.log(process.env.DEV); // false","lang":"typescript","description":"Shows basic usage of esbuild-plugin-env: import, call env() in plugins array, and access variables from .env via process.env."},"warnings":[{"fix":"Use `startKey` instead of `startkey` in the options object.","message":"In v1.1.0, the option `startkey` was renamed to `startKey` (camelCase). Using `startkey` will be ignored silently.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Ensure your .env keys start with `ESB_` (or the configured startKey).","message":"The plugin only defines environment variables with a prefix (default `ESB_`). Variables without the prefix are not included.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Explicitly set `isProd: true` in options if you want production behavior without minification.","message":"`process.env.NODE_ENV` is set to 'production' only when `minify: true` or `isProd: true`. Otherwise it remains undefined (not 'development').","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use dotenv's path option by calling `require('dotenv').config({ path: '/custom/path' })` before running esbuild.","message":"The plugin does not automatically load .env files from custom paths. It uses dotenv's default behavior (looks for .env in cwd).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `npm install esbuild-plugin-env --save-dev` or check that the package is listed in devDependencies.","cause":"Package not installed or incorrect import path.","error":"Error: Cannot find module 'esbuild-plugin-env'"},{"fix":"Use `import env from 'esbuild-plugin-env'` (default import) instead of `import { env } from 'esbuild-plugin-env'`.","cause":"Named import instead of default import.","error":"TypeError: (0 , plugin_env_1.default) is not a function"},{"fix":"Create a .env file in the root of your project or use dotenv's config to specify a path before building.","cause":"No .env file exists in the current working directory.","error":"Error: No env file found"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}