Registry / web-framework / koa-parcel-middleware

koa-parcel-middleware

JSON →
library1.0.3jsnpmunverified

koa-parcel-middleware is a Koa.js middleware designed to integrate the Parcel bundler's functionality directly into a Koa application. This enables developers to serve their UI applications from the same Koa server, leverage Parcel's development server features like Hot Module Replacement (HMR) within an existing server setup, and implement advanced techniques such as server-side rendering (SSR) for isomorphic JavaScript. The package is currently at version 1.0.3, with its last release in 2019, indicating an abandoned or unmaintained status. Its primary differentiator is the seamless integration of Parcel v1's bundling capabilities with Koa's middleware stack, obviating the need for a separate Parcel dev server process.

npm install koa-parcel-middleware
INSTALL
IMPORT
SIG · KOA-PARCEL-MIDDLEW
K
koa-parcel-middleware
web-frameworkjavascriptv1.0.3
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.

createMiddleware
import { createMiddleware } from 'koa-parcel-middleware'
import createMiddleware from 'koa-parcel-middleware'
This is the primary named export for modern ES module environments or TypeScript projects. Attempting to use a default import will result in an undefined value.
createMiddleware (CommonJS)
const { createMiddleware } = require('koa-parcel-middleware')
const createMiddleware = require('koa-parcel-middleware')
For CommonJS environments, ensure you destructure the `createMiddleware` function from the module object, as it is a named export, not a default export.
KoaParcelMiddlewareOptions
import { KoaParcelMiddlewareOptions } from 'koa-parcel-middleware'
This package includes TypeScript typings. If you need to type the options object passed to `createMiddleware`, import the `KoaParcelMiddlewareOptions` interface (or similar, depending on the exact export name) for strict type checking.

This example demonstrates how to set up a Koa server with `koa-parcel-middleware` to bundle and serve a UI application. It includes Parcel v1 configuration, optional server-side rendering (SSR) integration, and static asset serving using `koa-static`.

import { createMiddleware } from 'koa-parcel-middleware' import { promises as fs } from 'fs' import * as path from 'path' import * as ReactDOMServer from 'react-dom/server' import Bundler from 'parcel-bundler' import CombinedStream from 'combined-stream' import Koa from 'koa' import serveStatic from 'koa-static' // Your Parcel application's unbuilt entry point const ENTRY_FILENAME = path.resolve(__dirname, 'index.html') const isDev = process.env.NODE_ENV === 'development' async function start () { const app = new Koa() // Your Parcel application's built entry point const outFile = path.resolve(__dirname, 'dist', 'index.html') const outDir = path.resolve(__dirname, 'dist') const options = { outDir, outFile, watch: isDev, minify: !isDev, scopeHoist: false, hmr: isDev, detailedReport: isDev } const bundler = new Bundler(ENTRY_FILENAME, options) bundler.bundle() // Initiate Parcel bundling const staticMiddleware = serveStatic(outDir) const parcelMiddleware = createMiddleware({ bundler, renderHtmlMiddleware: async (ctx, next) => { // Optionally wire in Server-Side Rendering (SSR) here const outFileBuffer = await fs.readFile(outFile) const [preAppEntry, postAppEntry] = outFileBuffer.toString() .split(/<!--.*ssr.*-->/) ctx.status = 200 const htmlStream = new CombinedStream() ;[ preAppEntry, ReactDOMServer.renderToNodeStream(/** Your React App component here **/ null), postAppEntry ].map(content => htmlStream.append(content)) ctx.body = htmlStream ctx.type = 'html' await next() }, staticMiddleware }) app.use((ctx, next) => parcelMiddleware(ctx, next)) app.listen(3000, () => console.log('Koa server with Parcel middleware running on port 3000')) } start().catch(console.error)
Debug
Known issues
breakingThis middleware is designed for and implicitly relies on Parcel v1 (`parcel-bundler`). It is not compatible with Parcel v2, which introduced significant breaking API changes. Attempting to use it with Parcel v2 will lead to runtime errors due to API mismatches.
fix
Ensure you are using `parcel-bundler` (Parcel v1) in your project. If you need Parcel v2, consider alternatives or manually integrate Parcel's middleware for Koa.
affects: >=1.0.0
gotchaThe package has not been updated since July 2019, indicating it is no longer actively maintained. This means it may not receive bug fixes, security updates, or compatibility updates for newer versions of Node.js, Koa, or other dependencies.
fix
Be aware of potential compatibility issues with newer ecosystems. Consider forking the repository for custom maintenance or explore more actively maintained alternatives if long-term support is critical.
affects: >=1.0.3
gotchaThis package lists `koa` (>=2) and `koa-static` (>=4) as peer dependencies. These must be explicitly installed in your project, otherwise, the middleware will fail to function due to missing modules.
fix
Install peer dependencies: `npm install koa koa-static` or `yarn add koa koa-static`.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'koa' or 'koa-static'
One of the required peer dependencies (koa or koa-static) has not been installed.
fix
Run `npm install koa koa-static` or `yarn add koa koa-static` in your project directory.
TypeError: bundler.bundle is not a function
You are likely attempting to use Parcel v2 (`parcel`) instead of Parcel v1 (`parcel-bundler`) with this middleware. Parcel v2 has a different API.
fix
Install `parcel-bundler` (Parcel v1) and ensure your code uses it: `npm install parcel-bundler` or `yarn add parcel-bundler`. Adjust `import Bundler from 'parcel-bundler'` accordingly.
TypeError: createMiddleware is not a function
This error often occurs when trying to use `require('koa-parcel-middleware')` and then directly calling it, or trying to use `import createMiddleware from 'koa-parcel-middleware'` (default import) instead of the correct named import.
fix
For CommonJS, use `const { createMiddleware } = require('koa-parcel-middleware')`. For ESM/TypeScript, use `import { createMiddleware } from 'koa-parcel-middleware'`.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
koarequiredRequired peer dependency for the Koa.js application framework.
koa-staticrequiredRequired peer dependency for serving static assets (e.g., CSS, images) built by Parcel.
Agent activity
2 hits · last 30 days
node
2
Resources
koa-parcel-middleware — npm install koa-parcel-middleware · libregistry