can not use
Closed this issue · 3 comments
@lglie Sorry for the bug. I will fix it (make it compatible with normal require
) and release a new version today.
The bug:
babel@6.x
compiled js file will export { default: xxx }
default. So you get not a function
error.
Workaround:
- If you use
ES2015
andBabel@6.x
, useimport xmlParser from 'koa-xml-body';
instead. - Or use
var xmlParser = require('koa-xml-body').default
@lglie As the lib is written in ES6
, See https://medium.com/@kentcdodds/misunderstanding-es6-modules-upgrading-babel-tears-and-a-solution-ad2d5ab93ce0#.e865sp7t8 for more details about babel6
info and ES6 export
.
And I finally decide to not change the export behavior. It means you should use the either way:
- traditional:
var xmlParser = require('koa-xml-body').default;
ES6+
withBabel6.x
:import xmlParser from 'koa-xml-body';
Very thank you for the bug report, and I'll release a new version to update readme with correct usage example. Thanks.
Thank you!------------------ Original ------------------
From: "Creeper"notifications@github.com
Date: Wed, Feb 10, 2016 11:32 PM
To: "creeperyang/koa-xml-body"koa-xml-body@noreply.github.com;
Cc: "lglie"532875676@qq.com;
Subject: Re: [koa-xml-body] can not use (#1)
@lglie As the lib is written in ES6, See https://medium.com/@kentcdodds/misunderstanding-es6-modules-upgrading-babel-tears-and-a-solution-ad2d5ab93ce0#.e865sp7t8 for more details about babel6 info and ES6 export.
And I finally decide to not change the export behavior. It means you should use the either way:
traditional: var xmlParser = require('koa-xml-body').default;
ES6+ with Babel6.x: import xmlParser from 'koa-xml-body';
Very thank you for the bug report, and I'll release a new version to update readme with correct usage example. Thanks.
—
Reply to this email directly or view it on GitHub.