Registry / devops / webpack-env

webpack-env

JSON →
library0.8.0jsnpmunverified

Webpack plugin that makes variables from a .env.js file available as global constants in your webpack bundles. Version 0.8.0 (latest) – no recent updates, low maintenance. Key differentiator: simple environment variable injection without additional loaders. Alternatives like dotenv-webpack offer more features and active support.

npm install webpack-env
INSTALL
IMPORT
SIG · WEBPACK-ENV
W
webpack-env
devopsjavascriptv0.8.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

webpackEnv
✓ const webpackEnv = require('webpack-env')
✗ import webpackEnv from 'webpack-env'
CJS only; no ESM exports.
.env.js
✓ module.exports = { MY_VAR: 'value' }
✗ export default { MY_VAR: 'value' }
Must use CommonJS exports; ES module exports not supported.
Plugin usage in webpack config
✓ plugins: [new webpack.webpackEnv()] or plugins: [require('webpack-env')]
✗ plugins: [new WebpackEnv()]
The plugin itself is the required function; no instantiation with new.

Sets up webpack-env plugin with gulp and a .env.js file defining globals.

// gulpfile.js const gulp = require('gulp'); const webpack = require('webpack'); const webpackEnv = require('webpack-env'); gulp.task('webpack', function() { return gulp.src('./entry.js') .pipe(webpack({ output: { filename: 'bundle.js' }, plugins: [webpackEnv] })) .pipe(gulp.dest('build/')); }); // .env.js (in project root) module.exports = { MY_API_URL: 'https://api.example.com', DEBUG: true };
Debug
Known issues
gotchaPlugin is used directly without instantiation (new) – passing the required function as a plugin.
fix
Use plugins: [require('webpack-env')] not plugins: [new require('webpack-env')]
affects: >=0.0.0
gotcha.env.js must use CommonJS (module.exports) not ES module export.
fix
Use module.exports = { ... } instead of export default { ... }
affects: >=0.0.0
deprecatedPackage is unmaintained; no updates for years; consider dotenv-webpack for active development.
fix
Migrate to dotenv-webpack: install dotenv-webpack and use new Dotenv() in plugins.
affects: >=0.0.0
gotchaOnly supports single .env.js file; multiple environments require separate files like .production_env.js but no documented override order.
fix
Manually set NODE_ENV before build to switch files.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: webpackEnv is not a constructor
Using new webpackEnv() when plugin should be passed directly.
fix
Use plugins: [require('webpack-env')] instead of plugins: [new require('webpack-env')]
Module not found: Error: Can't resolve 'fs' in ...
webpack-env uses Node.js fs module; incompatible with webpack 4+/5 in browser environment.
fix
Not recommended for browser-only build; use dotenv-webpack or DefinePlugin.
ReferenceError: SOME_VAR is not defined
.env.js not being loaded or exported incorrectly.
fix
Create .env.js in project root with module.exports = { SOME_VAR: 'value' }
Warning: webpack-env plugin: .env.js file is missing
No .env.js file found in project root.
fix
Create .env.js file in the root directory containing module.exports = { ... }
Upgrade
Version history
0.8.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
webpack-env — npm install webpack-env · libregistry