koa2-formidable is a Koa 2 middleware designed to parse multipart/form-data requests, primarily for file uploads and complex form submissions. It acts as a wrapper around the popular `formidable` library, simplifying its integration into Koa applications. The package is currently at version 1.0.3 and has not seen any updates or releases in over five years, indicating it is no longer actively maintained. This contrasts sharply with the underlying `formidable` library, which is actively developed and has moved to major versions 3 and 4, introducing ESM support, modern Node.js stream compatibility, and crucial security updates. As such, `koa2-formidable` relies on an outdated version of `formidable`, making it unsuitable for modern Koa projects due to potential security vulnerabilities, lack of current features, and compatibility issues with newer Node.js runtimes.
npm install koa2-formidableVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `koa2-formidable` in a Koa application to handle multipart/form-data uploads, including file and field parsing, and how to access the processed data via `ctx.request.body` and `ctx.request.files`.
Migrate to actively maintained Koa body parsing middleware like `@koa/body` or `koa-body`, which use up-to-date versions of `formidable` or other robust parsers. If direct `formidable` integration is preferred, use the `formidable` library directly with careful implementation, passing `ctx.req` (Node.js Request) to `formidable`'s `parse` method.
For new projects or existing ESM projects, prefer middlewares that offer native ESM support. If forced to use, integrate via `import pkg = require('pkg')` in TypeScript or dynamic `import()` in JavaScript, though this is generally discouraged for middleware.Avoid using this package in production. If currently in use, plan for migration to an actively maintained alternative to ensure stability, security, and long-term compatibility.
For fine-grained control over `formidable`'s capabilities, consider using the `formidable` library directly within your Koa routes. This allows direct access to `formidable`'s `IncomingForm` instance and its full API.
This warning cannot be fixed within `koa2-formidable` itself. The only resolution is to replace `koa2-formidable` with an actively maintained Koa body parsing middleware that uses a current version of `formidable` (v3+) or an alternative parser. Consider `koa-body` or `@koa/body`.
Ensure your file is treated as a CommonJS module (e.g., a `.js` file without `"type": "module"` in `package.json`). Alternatively, if your project is ESM, you must use dynamic `import()`: `const formidable = await import('koa2-formidable');`, though this is generally not recommended for middleware due to its asynchronous nature.Ensure you are passing the `maxFieldsSize` and `maxFileSize` options correctly to the `formidable` middleware. For example: `app.use(formidable({ maxFieldsSize: 20 * 1024 * 1024, maxFileSize: 200 * 1024 * 1024 }));` (for 20MB fields and 200MB files). If problems persist, this may indicate a limitation of the old `formidable` version, requiring migration to a modern alternative.