koajs / koa-body

koa body parser middleware
MIT License
947 stars 131 forks source link

require('koa-body/unparsed.js') throws MODULE_NOT_FOUND error #222

Open tafel opened 1 year ago

tafel commented 1 year ago

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

cedx commented 4 months ago

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")];