{"id":25183,"library":"dotenv-esbuild","title":"dotenv-esbuild","description":"A simple esbuild plugin that integrates dotenv to load environment variables during the build process. Version 1.1.0, released as a stable package with TypeScript type definitions. It replaces traditional dotenv usage by injecting variables at build time, ensuring consistency across environments. The plugin supports custom .env file paths and is designed for projects using esbuild. It has minimal configuration and is actively maintained.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/havkin/dotenv-esbuild","tags":["javascript","dotenv","env","esbuild","plugin","typescript"],"install":[{"cmd":"npm install dotenv-esbuild","lang":"bash","label":"npm"},{"cmd":"yarn add dotenv-esbuild","lang":"bash","label":"yarn"},{"cmd":"pnpm add dotenv-esbuild","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency, required for plugin integration","package":"esbuild","optional":false},{"reason":"Used to parse .env files, but bundled internally","package":"dotenv","optional":true}],"imports":[{"note":"ESM-only package, default export is a class constructor. CommonJS require will fail.","wrong":"const Dotenv = require('dotenv-esbuild')","symbol":"Dotenv","correct":"import Dotenv from 'dotenv-esbuild'"},{"note":"Named export is available since v1.0.0, but default export is the same class. Both work.","wrong":"import Dotenv from 'dotenv-esbuild'","symbol":"Dotenv","correct":"import { Dotenv } from 'dotenv-esbuild'"},{"note":"Type import only, cannot be used at runtime.","wrong":"import { DotenvPluginOptions } from 'dotenv-esbuild'","symbol":"DotenvPluginOptions","correct":"import type { DotenvPluginOptions } from 'dotenv-esbuild'"}],"quickstart":{"code":"import esbuild from 'esbuild';\nimport Dotenv from 'dotenv-esbuild';\n\nawait esbuild.build({\n  entryPoints: ['src/index.ts'],\n  bundle: true,\n  outfile: 'dist/bundle.js',\n  plugins: [\n    new Dotenv({\n      path: './.env',\n    }),\n  ],\n});\n\nconsole.log('Build complete with environment variables injected.');","lang":"typescript","description":"Shows minimal configuration to use dotenv-esbuild plugin with esbuild."},"warnings":[{"fix":"Use `new Dotenv()` or `{ Dotenv }` named import.","message":"v1.0.0 changed from default export being an object to a class constructor","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Access process.env directly in code instead.","message":"Option `systemvars` was removed in v1.0.0","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure you use the build API, not transform.","message":"Plugin only works with esbuild's `build` and `buildSync` API, not `transform`","severity":"gotcha","affected_versions":"*"},{"fix":"Rebuild project to pick up new env values.","message":"Environment variables are injected at build time; runtime changes to .env will be ignored","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `import Dotenv from 'dotenv-esbuild'` and then `new Dotenv()`.","cause":"Using an older import pattern or not using `new` with the default export.","error":"TypeError: Dotenv is not a constructor"},{"fix":"Install dotenv as a dependency: `npm install dotenv`.","cause":"The package expects dotenv to be installed or bundled incorrectly.","error":"Error: [plugin: dotenv-esbuild] Cannot find module 'dotenv'"},{"fix":"Run `npm install dotenv-esbuild --save-dev` and ensure it's in node_modules.","cause":"Package not installed or npm/node_modules not found.","error":"Module not found: Error: Can't resolve 'dotenv-esbuild'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}