koajs / bodyparser

Koa body parsing middleware
MIT License
1.31k stars 116 forks source link

4.1 Unexpected token function #69

Closed zymt closed 7 years ago

zymt commented 7 years ago

bodyparser(4.1) in Koa(2.2.0)

just use like app.use(bodyParser());

error showed as below:

/some/path/node_modules/koa-bodyparser/index.js:69
  return async function bodyParser(ctx, next) {
               ^^^^^^^^
SyntaxError: Unexpected token function
    at Object.exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:513:28)
    at Module._extensions..js (module.js:550:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/zhangyan/Documents/Zalaxy/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/some/path/server/app.js:4:20)
dead-horse commented 7 years ago

ensure your node version is >=7.6.0

xiaohanzhang commented 7 years ago

@dead-horse Shall we consider support node 6? Since node 6.10.0 LTS is still the officially recommended version.

achillesye commented 7 years ago

Finally how did you deal with?

KrekkieD commented 7 years ago

@xiaohanzhang I would very much appreciate that. In an enterprise environment it's hard to sell Node v7.

PeterHewat commented 7 years ago

Hello,

To my understanding, Koa v2.x is forward looking where as v1.x is the stable/production branche.

In our production environment, we use node v6 with koa v1. Here is our dependencies in package.json file:

"dependencies": { "co-body": "^4.2.0", "koa": "^1.2.4", "koa-router": "^5.4.0", ... }

We will move to koa v2 in production only when node v8 LTS comes out (with all its async await goodness).

Hence Yiyu He, was right in closing this non issue.

Regards, Peter

On Thu, Apr 13, 2017 at 8:57 PM, Gregory Cowan notifications@github.com wrote:

@xiaohanzhang https://github.com/xiaohanzhang I would very much appreciate that. In an enterprise environment it's hard to sell Node v7.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/koajs/bodyparser/issues/69#issuecomment-293991498, or mute the thread https://github.com/notifications/unsubscribe-auth/AO7iauXAbAHipuc-jiKib_Eln_gUnw9Aks5rvnAigaJpZM4Me6T6 .

dschinkel commented 7 years ago

so koa-bodyparser doesn't work with Koa v2 yet?

struCoder commented 7 years ago

this is okay

const babelrc = {
  "ignore": /node_modules\/(?!(koa-bodyparser)\/).*/,
  "presets": ["node6"],
  "plugins": [
    "transform-class-properties",
    "transform-async-to-generator"
  ]
}
schtauffen commented 6 years ago

I've forked this module, made it compatible with node v6 and have published it to npm. yarn add koa-bodyparser-node6 caveat: you cannot count that I keep up with the latest version at all times :)