{"id":18479,"library":"koa2-connect","title":"koa2-connect","description":"A small utility (v1.0.2, last updated 2019) that adapts Connect/Express-style middleware (req, res, next) to work with Koa 2.x async middleware (ctx, next). Unlike koa-connect, koa2-connect is designed to better support streaming middleware like webpack-dev-middleware and webpack-hot-middleware. It is a stopgap for when Koa-native alternatives are unavailable; not recommended for new projects where Koa-native middleware exists.","status":"maintenance","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/cyrilluce/koa2-connect","tags":["javascript","koa","koa2","connect","express","middleware"],"install":[{"cmd":"npm install koa2-connect","lang":"bash","label":"npm"},{"cmd":"yarn add koa2-connect","lang":"bash","label":"yarn"},{"cmd":"pnpm add koa2-connect","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"No default ESM export; use CommonJS require or synthetic default import.","wrong":"import c2k from 'koa2-connect'","symbol":"c2k","correct":"const c2k = require('koa2-connect')"},{"note":"The module exports a single function; named imports like convert are incorrect.","wrong":"import { convert } from 'koa2-connect'","symbol":"default","correct":"const conv = require('koa2-connect')"},{"note":"Directly using Express middleware without wrapping will break because Koa expects a different signature.","wrong":"app.use(someExpressMiddleware)","symbol":"Promise","correct":"const c2k = require('koa2-connect'); app.use(c2k(someExpressMiddleware))"}],"quickstart":{"code":"const Koa = require('koa');\nconst c2k = require('koa2-connect');\nconst app = new Koa();\n\n// Express-style middleware\nfunction expressMiddleware(req, res, next) {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('Hello from Express');\n  next();\n}\n\napp.use(c2k(expressMiddleware));\napp.use((ctx) => {\n  ctx.body = 'Koa response';\n});\n\napp.listen(3000);","lang":"javascript","description":"Wrap an Express-style middleware with c2k and use it in a Koa app."},"warnings":[{"fix":"Ensure your Express middleware invokes next() when done, or use a Koa-native alternative.","message":"Express middleware must call next() to allow Koa middleware downstream to execute.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Install @types/koa2-connect if available, or declare module 'koa2-connect' { ... }.","message":"The module does not provide types; you may need to add your own type declarations.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Consider migrating to native Koa middleware or using koa-connect as an alternative.","message":"Package is in maintenance mode with no updates since 2019. Known issues may not be fixed.","severity":"deprecated","affected_versions":">=1.0"},{"fix":"Use a Koa-native error handler or wrap errors manually using try/catch inside the Express middleware.","message":"Express middleware that relies on synchronous response methods (e.g., res.sendStatus) may not trigger Koa's error handling correctly.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure the middleware is compatible with Connect/Express and always calls next().","cause":"Your Express middleware expects a next callback, but koa2-connect may not pass one in certain failure cases.","error":"Error: next is not a function"},{"fix":"Use only raw Node.js http methods (res.writeHead, res.end) and avoid Express-specific functions like res.status.","cause":"The Express middleware tried to access res.status, but Koa's response object has a different API.","error":"TypeError: Cannot read property 'status' of undefined"},{"fix":"Use dynamic import: const c2k = (await import('koa2-connect')).default;","cause":"You are using ESM (ES modules) and need to use import instead of require.","error":"ReferenceError: require is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}