envkey-webpack-plugin

raw JSON →
2.5.1 verified Fri May 01 auth: no javascript

A webpack plugin that wraps EnvKey's Node.js library to inject allow-listed environment variables from EnvKey into browser apps via process.env. Version 2.5.1 is stable; the package is part of the EnvKey ecosystem (encrypted environment variable management). Unlike generic dotenv plugins, this fetches variables from EnvKey servers using an ENVKEY, with an allow-list (permitted) to avoid leaking secrets. Requires webpack as a peer dependency. Release cadence is irregular, tied to EnvKey platform updates.

error Error: Cannot find module 'envkey-webpack-plugin'
cause Package not installed or not installed as dev dependency.
fix
Run npm install envkey-webpack-plugin --save-dev in your project root.
error TypeError: EnvkeyWebpackPlugin is not a constructor
cause Incorrect import (ESM default import in CommonJS context) or using an outdated version that exports differently.
fix
Use const EnvkeyWebpackPlugin = require('envkey-webpack-plugin'); (CommonJS) instead of import.
error Error: ENVKEY not found. Please set ENVKEY environment variable or include it in your dotenv file.
cause Missing or invalid ENVKEY in environment or .env file.
fix
Add ENVKEY=your_key to the .env file (or set it as an environment variable). Ensure the key is valid and not expired.
gotcha All variables from EnvKey are injected into process.env, but only those in the 'permitted' list are allowed. Unlisted vars will be ignored.
fix Explicitly list every variable you want available in the browser in the 'permitted' array. Do not rely on default behavior to include anything.
deprecated Old versions may not support the 'dotEnvFile' option. Always check compatibility with your webpack version.
fix Upgrade to v2+ or pass ENVKEY via environment variable directly before webpack build.
gotcha The plugin only works at build time; variables are statically replaced via webpack's DefinePlugin. Runtime changes to EnvKey will not be reflected until a new build.
fix Rebuild the application to pick up updated environment variable values. This is expected behavior for compile-time injection.
gotcha Using 'define' overrides variables with the same name from EnvKey. Order: EnvKey values are loaded first, then 'define' values overwrite them.
fix If you want EnvKey values to take precedence, do not include them in 'define'. Check for naming conflicts.
gotcha The plugin requires a valid ENVKEY to be present either in the dotEnvFile or as an environment variable in the build process. Missing ENVKEY causes build failure.
fix Ensure your .env file has ENVKEY=... or set the ENVKEY environment variable in your CI/build system.
npm install envkey-webpack-plugin
yarn add envkey-webpack-plugin
pnpm add envkey-webpack-plugin

Basic configuration of envkey-webpack-plugin with required permitted list and optional dotEnvFile and define options.

// webpack.config.js
const EnvkeyWebpackPlugin = require('envkey-webpack-plugin');

module.exports = {
  // ... other config
  plugins: [
    new EnvkeyWebpackPlugin({
      permitted: ['API_URL', 'PUBLIC_KEY'],
      dotEnvFile: '.env',
      define: { ADDITIONAL: 'value' }
    })
  ]
};