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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default
✓ import webpackAssets from 'express-webpack-assets'
✗ const webpackAssets = require('express-webpack-assets')
ESM import works as the module has a default export.
webpack_asset
✓ <!-- Available in template locals after middleware is applied: webpack_asset('one', 'js') -->
✗ Using webpack_assets (plural) instead of webpack_asset (singular)
The helper is injected as a local variable named 'webpack_asset'.
options
✓ app.use(webpackAssets('./config/webpack-assets.json', { devMode: false }))
✗ app.use(webpackAssets({ path: './config/webpack-assets.json' }))
The first argument is a path string, not an options object.
Sets up Express middleware to load a webpack assets JSON file and expose the `webpack_asset` helper in templates.
import express from 'express';
import webpackAssets from 'express-webpack-assets';
const app = express();
app.set('view engine', 'ejs');
// Load asset manifest and inject webpack_asset helper into res.locals
app.use(webpackAssets('./config/webpack-assets.json', { devMode: false }));
app.get('/', (req, res) => {
// In the EJS template, use: <script src="<%= webpack_asset('one', 'js') %>"></script>
res.render('index');
});
app.listen(3000);
Errors
Common errors & fixes
Cannot read property 'js' of undefined
The asset key or file type does not exist in the loaded manifest JSON.
fixVerify the manifest file contains the expected asset keys (e.g., 'one') and file types (e.g., 'js').
Error: ENOENT: no such file or directory, open './config/webpack-assets.json'
The path provided to the middleware does not point to an existing file or directory.
fixEnsure the path is correct relative to the project root or use an absolute path.
webpack_asset is not defined
The middleware did not run before the template rendering, or the path is invalid causing the helper not to be injected.
fixEnsure `app.use(webpackAssets(...))` is placed before any route handlers that render templates.
TypeError: webpackAssets is not a function
Importing the module incorrectly (e.g., using named import instead of default import).
fixUse `import webpackAssets from 'express-webpack-assets'` or `const webpackAssets = require('express-webpack-assets').default` in CommonJS. Audit
Dependencies
expressoptionalPeer dependency for Express middleware
assets-webpack-pluginrequiredRequired to generate the webpack-assets.json manifest file