{"id":10662,"library":"connect-next","title":"Connect-Next Middleware Framework","description":"connect-next is an actively maintained fork of the classic Connect middleware framework for Node.js, providing a high-performance, pluggable HTTP server framework built around a \"middleware\" stack. The current stable version is 4.0.1, released as part of an active development cadence. Key differentiators from the original Connect include a complete rewrite in TypeScript, native ES module (ESM) publication, and a stricter Node.js engine requirement (currently `^20.19.0 || >=22.12.0`). It also ships with its own TypeScript types, eliminating the need for `@types/connect`. The project modernizes the proven Connect architecture, ensuring compatibility with contemporary Node.js practices and providing a robust foundation for web applications.","status":"active","version":"4.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/rstackjs/connect-next","tags":["javascript"],"install":[{"cmd":"npm install connect-next","lang":"bash","label":"npm"},{"cmd":"yarn add connect-next","lang":"bash","label":"yarn"},{"cmd":"pnpm add connect-next","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v4, connect-next is a native ES module (ESM) and exposes a named 'connect' export, unlike the original 'connect' which used a default export.","wrong":"import connect from 'connect-next';","symbol":"connect","correct":"import { connect } from 'connect-next';"},{"note":"connect-next is an ES module only. Direct CommonJS 'require()' is not supported; use dynamic import() if absolutely necessary within CJS contexts, or convert your project to ESM.","wrong":"const connect = require('connect-next');","symbol":"connect (CommonJS)","correct":"N/A"},{"note":"While 'NextFunction' is not directly exported, 'connect-next' ships with its own TypeScript types. Middleware typically takes (req: IncomingMessage, res: ServerResponse, next: NextFunction) => void. 'NextFunction' represents (err?: any) => void.","symbol":"Middleware types","correct":"import type { IncomingMessage, ServerResponse } from 'node:http';\nimport type { NextFunction } from 'connect-next';"}],"quickstart":{"code":"import { connect } from 'connect-next';\nimport { createServer } from 'node:http';\nimport compression from 'compression';\nimport cookieSession from 'cookie-session';\nimport bodyParser from 'body-parser';\n\nconst app = connect();\n\n// gzip/deflate outgoing responses\napp.use(compression());\n\n// store session state in browser cookie\napp.use(\n  cookieSession({\n    keys: ['secret1', 'secret2'],\n  }),\n);\n\n// parse urlencoded request bodies into req.body\napp.use(bodyParser.urlencoded({ extended: false }));\n\n// respond to all requests\napp.use((req, res) => {\n  res.end('Hello from Connect!\\n');\n});\n\n// create an HTTP server and listen on port 3000\ncreateServer(app).listen(3000);","lang":"javascript","description":"Demonstrates creating a basic Connect-Next application, adding common middleware for compression, session management, and body parsing, then listening for HTTP requests."},"warnings":[{"fix":"Upgrade your Node.js environment to a compatible version.","message":"Connect-Next requires Node.js version `^20.19.0 || >=22.12.0`. Older Node.js versions are not supported and will result in errors upon installation or execution.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Ensure your project is configured for ESM (e.g., via `\"type\": \"module\"` in `package.json` or by using `.mjs` extensions) and use `import { connect } from 'connect-next';`.","message":"Connect-Next is published as a native ES module (ESM) and only supports 'import' syntax. CommonJS 'require()' calls will fail.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Change `import connect from 'connect';` to `import { connect } from 'connect-next';` and remove `@types/connect` from your dependencies.","message":"When migrating from the original `connect` package, note that `connect-next` exposes a named `connect` export, not a default one. Additionally, `@types/connect` is no longer needed as types are included.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Define error middleware with the signature `(err: Error, req: IncomingMessage, res: ServerResponse, next: NextFunction) => void;`.","message":"Error-handling middleware must explicitly take four arguments: `(err, req, res, next)`. Middleware with fewer arguments are treated as regular middleware and will not catch errors passed to `next()`.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Refactor your import statement from `const connect = require('connect-next');` to `import { connect } from 'connect-next';` and ensure your project uses ES modules.","cause":"Attempting to use CommonJS `require()` to import `connect-next`, which is a native ES module.","error":"ERR_REQUIRE_ESM: require() of ES Module ... connect-next/index.js from ... not supported."},{"fix":"Change your import statement from `import connect from 'connect-next';` to `import { connect } from 'connect-next';`.","cause":"You are attempting to use a default import for `connect-next`, but it only exposes a named `connect` export.","error":"TypeError: connect_next_1.default is not a function"},{"fix":"Ensure your `package.json` has `\"type\": \"module\"` if you intend to use ESM globally, or use `.mjs` file extensions for individual ES module files. Always use `import { connect } from 'connect-next';`.","cause":"Your Node.js environment or file is configured for CommonJS, but `connect-next` is an ES module.","error":"SyntaxError: Must use import to load ES Module: ...connect-next/index.js"}],"ecosystem":"npm"}