{"id":20022,"library":"express-webpack-assets","title":"express-webpack-assets","description":"Express middleware that loads hashed Webpack asset manifests generated by assets-webpack-plugin, exposing asset paths (JS, CSS, etc.) to templates via a `webpack_asset()` helper. Version 0.1.0 is the latest stable release. It supports single or multiple JSON manifest files (merged in filesystem order). Useful for referencing versioned assets without hardcoding hashes. Not actively maintained; alternatives include webpack-manifest-plugin with express middleware.","status":"maintenance","version":"0.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/auchenberg/express-webpack-asset","tags":["javascript"],"install":[{"cmd":"npm install express-webpack-assets","lang":"bash","label":"npm"},{"cmd":"yarn add express-webpack-assets","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-webpack-assets","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for Express middleware","package":"express","optional":true},{"reason":"Required to generate the webpack-assets.json manifest file","package":"assets-webpack-plugin","optional":false}],"imports":[{"note":"ESM import works as the module has a default export.","wrong":"const webpackAssets = require('express-webpack-assets')","symbol":"default","correct":"import webpackAssets from 'express-webpack-assets'"},{"note":"The helper is injected as a local variable named 'webpack_asset'.","wrong":"Using webpack_assets (plural) instead of webpack_asset (singular)","symbol":"webpack_asset","correct":"<!-- Available in template locals after middleware is applied: webpack_asset('one', 'js') -->"},{"note":"The first argument is a path string, not an options object.","wrong":"app.use(webpackAssets({ path: './config/webpack-assets.json' }))","symbol":"options","correct":"app.use(webpackAssets('./config/webpack-assets.json', { devMode: false }))"}],"quickstart":{"code":"import express from 'express';\nimport webpackAssets from 'express-webpack-assets';\n\nconst app = express();\napp.set('view engine', 'ejs');\n// Load asset manifest and inject webpack_asset helper into res.locals\napp.use(webpackAssets('./config/webpack-assets.json', { devMode: false }));\n\napp.get('/', (req, res) => {\n  // In the EJS template, use: <script src=\"<%= webpack_asset('one', 'js') %>\"></script>\n  res.render('index');\n});\n\napp.listen(3000);","lang":"javascript","description":"Sets up Express middleware to load a webpack assets JSON file and expose the `webpack_asset` helper in templates."},"warnings":[{"fix":"Use a single JSON file or ensure unique property names across files.","message":"When passing a directory path, the order of merging JSON files is determined by filesystem read order (not alphabetical), which can cause unexpected overrides.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Access the helper only within templates rendered after the middleware runs.","message":"The `webpack_asset` helper is attached as a local variable to Express `res.locals`, so it is only available in templates that are rendered from the same response context.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Migrate to a more modern asset management solution.","message":"The package is no longer actively maintained; consider using webpack-manifest-plugin with a custom Express middleware.","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Verify the manifest file contains the expected asset keys (e.g., 'one') and file types (e.g., 'js').","cause":"The asset key or file type does not exist in the loaded manifest JSON.","error":"Cannot read property 'js' of undefined"},{"fix":"Ensure the path is correct relative to the project root or use an absolute path.","cause":"The path provided to the middleware does not point to an existing file or directory.","error":"Error: ENOENT: no such file or directory, open './config/webpack-assets.json'"},{"fix":"Ensure `app.use(webpackAssets(...))` is placed before any route handlers that render templates.","cause":"The middleware did not run before the template rendering, or the path is invalid causing the helper not to be injected.","error":"webpack_asset is not defined"},{"fix":"Use `import webpackAssets from 'express-webpack-assets'` or `const webpackAssets = require('express-webpack-assets').default` in CommonJS.","cause":"Importing the module incorrectly (e.g., using named import instead of default import).","error":"TypeError: webpackAssets is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}