koa-body
koa-body copied to clipboard
require('koa-body/unparsed.js') throws MODULE_NOT_FOUND error
Describe the bug
Node.js version: 18.12.0
OS version: docker node:18.12.0-bullseye
Description:
Documentation says that unparsed body can be accessed with const unparsed = require('koa-body/unparsed.js');. But it throws an error instead.
Actual behavior
MODULE_NOT_FOUND : Cannot find module 'koa-body/unparsed.js'
Expected behavior
It should require the unparsed script
Code to reproduce
const unparsed = require('koa-body/unparsed.js');
Fix suggestion
Maybe it is not the best fix, but it is possible to require the file by changing the path:
const unparsed = require('koa-body/lib/unparsed.js').default;
If it is a viable solution, README.md should be updated to reflect this.
Checklist
- [x] I have searched through GitHub issues for similar issues.
- [x] I have completely read through the README and documentation.
- [x] I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.
Note that the unparsedBody symbol can be used directly (i.e. without first importing it). Like this:
const rawBody = ctx.request.body[Symbol.for("unparsedBody")];