-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix] @6.0.0 koaBody is not a function #215
Comments
|
@risu-p As @sschen86 mentioned correctly
You decide 🦺 This is only a problem when using the module with commonJS require not for import / export |
It is currently also not possible to use koaBody in a typescript esm project. If you |
@lbesson but this was also not possible before since it never exported an esm module or am i wrong? |
@TheDadi I'm still looking at it. But I can confirm that this was working with versions 5.0.0 (and previous ones) with my setup (typescript + esm), and not anymore since 6.0.0 (see for example c2corg/c2c_images#83). I'll investigate whenever I have time, and report whatever I find. |
I think we can just add a named export and change the docs to reflect that as the preferred usage pattern. I'm on vacation at the moment but can review a PR |
published + koa-body@6.0.1 |
@MarkHerhold is this the way now (ESM)? import body from 'koa-body';
const app = new koa();
app.use(body.default()); Because is a little bit sucky 😢 |
@damianobarbati try
|
Something is weird here, if you try
|
@saschanaz The NodeJS ESM loader supports importing CommonJS Modules (like koa-body). While importing it takes all named exports and puts them into a default export. This happens here: https://github.com/nodejs/node/blob/ecde9d9640e9b590a153c78b7dacc2739337f2a8/lib/internal/modules/esm/translators.js#L256 Its kind of a compatibility layer. What koa-body is doing right now (exporting "default" inside a CJS file) is not supported like they expected and will produce the error that was encountered here. More information on why this is happening: Bundlers take care of this as far as I understand, but the NodeJS default behavior for importing CJS into EMS is different. |
Describe the bug
Node.js version: v16.14.2
Description: @6.0.0 koaBody is not a function
Actual behavior
after install
koa-body@6.0.0
, get error: koaBody is not a functionback to
koa-body@5.0.0
everything is fineExpected behavior
need a doc for @6.0.0 😊
Code to reproduce
The text was updated successfully, but these errors were encountered: