{"id":16954,"library":"broccoli-middleware","title":"Broccoli Middleware","description":"broccoli-middleware is a utility that integrates the Broccoli asset pipeline's build output into standard Node.js HTTP servers, typically for development environments. It allows applications, especially those built with Ember CLI, to serve dynamically built assets through middleware like Express. The package is currently at version 2.1.1, with its last publication dating back to 2019. Its development is effectively abandoned, with no recent releases or active maintenance. It differentiates itself by providing a direct bridge between the Broccoli build process and a web server's request-response cycle, allowing for on-the-fly serving of compiled assets without a separate build step before server startup. This contrasts with build tools that pre-build all assets to a /dist folder.","status":"abandoned","version":"2.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/ember-cli/broccoli-middleware","tags":["javascript","builder","build","frontend","browser","asset","pipeline"],"install":[{"cmd":"npm install broccoli-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add broccoli-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add broccoli-middleware","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core asset pipeline this middleware integrates with.","package":"broccoli","optional":false},{"reason":"Common web framework for integration, though not a direct dependency, it's the typical use case.","package":"express","optional":true}],"imports":[{"note":"This package is CommonJS-only due to its age and target Node.js versions (Node 6-10). Native ESM import will fail.","wrong":"import broccoliMiddleware from 'broccoli-middleware';","symbol":"broccoliMiddleware","correct":"const broccoliMiddleware = require('broccoli-middleware');"}],"quickstart":{"code":"const express = require('express');\nconst path = require('path');\nconst fs = require('fs');\nconst broccoliMiddleware = require('broccoli-middleware');\n\n// Simulate a Broccoli builder output structure\nconst outputDir = path.join(__dirname, 'tmp/broccoli-output');\nfs.mkdirSync(outputDir, { recursive: true });\nfs.writeFileSync(path.join(outputDir, 'app.js'), 'console.log(\"Hello from Broccoli!\");');\nfs.writeFileSync(path.join(outputDir, 'styles.css'), 'body { background-color: lightblue; }');\n\nconst app = express();\n\n// In a real Ember CLI app, `watcher` and `builder` would be provided by ember-cli.\n// For this example, we'll mock the 'builder' interface to return a fixed directory.\nconst mockBuilder = {\n  // The `builder.outputPath` is what broccoli-middleware expects.\n  outputPath: outputDir\n};\n\napp.use(broccoliMiddleware(mockBuilder));\n\napp.get('/', (req, res) => {\n  res.send(`\n    <!DOCTYPE html>\n    <html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n        <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n        <title>Broccoli Middleware Example</title>\n        <link rel=\"stylesheet\" href=\"/styles.css\">\n    </head>\n    <body>\n        <h1>Welcome to Broccoli Middleware!</h1>\n        <script src=\"/app.js\"></script>\n        <p>Assets served dynamically from Broccoli's output.</p>\n    </body>\n    </html>\n  `);\n});\n\nconst PORT = process.env.PORT || 3000;\napp.listen(PORT, () => {\n  console.log(`Server listening on http://localhost:${PORT}`);\n  console.log('Try visiting http://localhost:3000/app.js and http://localhost:3000/styles.css');\n  console.log('Note: In a real scenario, mockBuilder would be a live Broccoli builder producing actual changes.');\n});\n\n// Cleanup on exit (optional for a quickstart, but good practice)\nprocess.on('exit', () => {\n  try { fs.rmSync(path.join(__dirname, 'tmp'), { recursive: true, force: true }); } catch (e) {}\n});\n","lang":"javascript","description":"This quickstart demonstrates how to set up `broccoli-middleware` with an Express server to serve assets from a simulated Broccoli build output directory. It shows basic integration for `app.js` and `styles.css`."},"warnings":[{"fix":"Consider migrating to modern asset bundling solutions like Webpack, Rollup, Parcel, or esbuild, which offer active maintenance and better compatibility. For Ember projects, leverage the built-in Ember CLI asset pipeline.","message":"broccoli-middleware is an abandoned project. It has not been updated since 2019 and targets older Node.js versions (6, 8, >=10). It is highly unlikely to be compatible with modern Node.js environments or current versions of Broccoli without significant workarounds.","severity":"breaking","affected_versions":">=2.1.1"},{"fix":"Ensure your project is configured for CommonJS or use dynamic `import()` if absolutely necessary within an ESM file (e.g., `const broccoliMiddleware = await import('broccoli-middleware');`). The preferred solution is to use `require` in a CJS file.","message":"This package uses CommonJS modules (`require`). Attempting to `import` it in an ESM context will result in a `SyntaxError: Cannot use import statement outside a module` or similar error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For new projects or migrations, evaluate contemporary build tools (e.g., Vite, Webpack, Parcel) and their native development servers or middleware integrations.","message":"While functional for its original purpose within Ember CLI, using `broccoli-middleware` outside of an existing legacy Ember CLI setup is strongly discouraged. Modern web development workflows provide more robust and actively maintained solutions for asset serving and bundling.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Rename your file to `.cjs` or ensure `\"type\": \"commonjs\"` is set in your `package.json`. If using an ES module, consider dynamic import: `const broccoliMiddleware = await import('broccoli-middleware');` or refactor the consuming code to use a CJS wrapper.","cause":"Attempting to use `require()` syntax for `broccoli-middleware` within a Node.js ES module file (e.g., a `.mjs` file or a `.js` file where `\"type\": \"module\"` is set in `package.json`). `broccoli-middleware` is a CommonJS module.","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"Ensure your session middleware (e.g., `express-session`) is configured with a `secret` option, for example: `app.use(session({ secret: process.env.SESSION_SECRET || 'a-very-secret-key', ... }));`.","cause":"Not directly related to `broccoli-middleware` itself, but often encountered when `broccoli-middleware` is used within larger Ember CLI setups that include Express or Connect servers with session middleware configured incorrectly or without a secret key.","error":"Error: The 'secret' option is required for sessions."}],"ecosystem":"npm","meta_description":null}