Registry / devops / node-config-webpack

node-config-webpack

JSON →
library1.0.10jsnpmunverified

node-config-webpack is a Webpack plugin designed to integrate the `config` module's functionality directly into Webpack builds. It replaces the dynamic runtime loading of configuration, characteristic of `node-config`, with a compile-time mechanism. This approach ensures that environment-specific configuration values are embedded directly into the bundled output, eliminating the need to include the `config` module as a runtime dependency for applications where configuration is static at build time. The plugin supports injecting configuration either into `process.env` (with options for key coercion to uppercase or direct object assignment) or as a global constant within the bundle. The current stable version is 1.0.10. While not under rapid development, it provides a stable solution for environments that leverage `node-config` and require optimized, compile-time configuration embedding, offering a direct integration path not typically found in generic Webpack `DefinePlugin` setups.

npm install node-config-webpack
INSTALL
IMPORT
SIG · NODE-CONFIG-WEBPAC
N
node-config-webpack
devopsjavascriptv1.0.10
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

NodeConfigWebpack
const NodeConfigWebpack = require('node-config-webpack');
import NodeConfigWebpack from 'node-config-webpack';
This plugin is typically imported using CommonJS `require()` in `webpack.config.js`. While modern Webpack configurations can use ESM, the package's primary distribution at version 1.0.10 uses CommonJS.
NodeConfigWebpack
plugins: [new NodeConfigWebpack()]
plugins: [NodeConfigWebpack()]
Webpack plugins must be instantiated with the `new` keyword when added to the `plugins` array of your webpack configuration.
NodeConfigWebpack (with options)
new NodeConfigWebpack({ env: true })
The plugin accepts an options object to customize its behavior, such as injecting config into `process.env` or as a global constant.

Demonstrates basic setup of `node-config-webpack` in `webpack.config.js` to inject configuration into `process.env` at compile time.

const NodeConfigWebpack = require('node-config-webpack'); const path = require('path'); module.exports = { mode: 'development', entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist'), }, plugins: [ new NodeConfigWebpack({ // Example: Inject config into process.env, coercing keys to uppercase env: true }) ], // Ensure 'config' module is not externalized if using node-externals externals: [ // In a server-side webpack config, if using webpack-node-externals, // you MUST allowlist 'config' for this plugin to work. // e.g., nodeExternals({ allowlist: ['config'] }) ] }; // src/index.js example (assuming you have a 'config' package and a 'config/default.json' with { "version": "1.0.0" }) // console.log('Configuration version is', process.env.VERSION); // Output: Configuration version is 1.0.0
Debug
Known issues
gotchaWhen using `webpack-node-externals` for server-side bundles, the `config` module *must* be added to its `allowlist` (whitelist). Failure to do so will cause `node-config-webpack` to fail, as the `config` module will be excluded from the bundle, preventing compile-time injection.
fix
Add `config` to the `allowlist` option of `webpack-node-externals`: `externals: [nodeExternals({ allowlist: ['config'] })]`.
affects: >=1.0.0
gotchaUsing `env: true` for the plugin option will coerce all root-level keys from your `node-config` into uppercase, mimicking typical `process.env` behavior. This might lead to unexpected variable names if your original config keys are not uppercase.
fix
If you need specific naming or wish to inject the entire config object under a single `process.env` key without coercion, use a string value for the `env` option, e.g., `new NodeConfigWebpack({ env: 'MY_APP_CONFIG' })`, then access as `process.env.MY_APP_CONFIG`.
affects: >=1.0.0
gotchaWhen using the `constant` option, ensure you reference the variable with the correct name. If `constant: true` is set, the variable will be `CONFIG`. If a string like `constant: 'myConfig'` is used, the variable will be `myConfig`.
fix
Verify the constant name used in your source code matches the `constant` option's value. E.g., for `constant: 'APP_CONFIG'`, use `APP_CONFIG.version` in your code.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: CONFIG is not defined
The `NodeConfigWebpack` plugin was not configured with the `constant: true` option, or a custom constant name was used but referenced incorrectly.
fix
Ensure your `webpack.config.js` includes `new NodeConfigWebpack({ constant: true })` or `new NodeConfigWebpack({ constant: 'YOUR_CONSTANT_NAME' })` and that your code references the constant by the correct name (e.g., `CONFIG.version` or `YOUR_CONSTANT_NAME.version`).
Module not found: Error: Can't resolve 'config' in [path]
This typically occurs in a Node.js-targeted Webpack build using `webpack-node-externals` where the `config` module is being excluded from the bundle.
fix
Modify your `webpack-node-externals` configuration to explicitly `allowlist: ['config']`. Example: `externals: [nodeExternals({ allowlist: ['config'] })]`.
process.env.MY_CUSTOM_KEY is undefined (when using env: true)
When `env: true` is used, `node-config-webpack` expects root-level key-value pairs in your `node-config` files and coerces keys to uppercase for `process.env`. If your original config uses lowercase or nested keys, they won't appear directly as `process.env.MY_CUSTOM_KEY`.
fix
Either ensure your `node-config` root keys are uppercase to match the `process.env` reference, or use `env: 'MAIN_CONFIG_VAR'` to inject the entire config object under a single `process.env` key (e.g., `process.env.MAIN_CONFIG_VAR.myCustomKey`).
Upgrade
Version history
1.0.10latest on npm
Audit
Dependencies
webpackrequiredPeer dependency; essential build tool for the plugin to operate.
configrequiredRuntime dependency; the plugin processes configuration files managed by the `config` module.
Agent activity
2 hits · last 30 days
node
2
Resources
node-config-webpack — npm install node-config-webpack · libregistry