Unexpected token function
printjs opened this issue · comments
I use typescript +koa2 +koa-static
environment
- node 6.10.2
- koa 2.3.0
- koa-static 4.0.1
- typescript 2.5.3
code
import serve = require("koa-static");
export const app = new Koa();
app.use(serve(__dirname + '/templates'));
error:
E:\frondend\koa-websocket\node_modules\koa-static\index.js:39
return async function serve (ctx, next) {
^^^^^^^^
SyntaxError: Unexpected token function
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (E:\frondend\koa-websocket\src\app.ts:5:1)
so,how to solve?
async function
needs node@7.6+ :)
since you are using ts
, you can translate async
to generator
:)
@coderhaoxin thank you.but, i have anthor question that koa-router
use async funcrtion
too,koa-router
is normal.why?
@wjtgithub koa-router
supports async function
, but doesn't using async function
in their code :)
@coderhaoxin Sorry, I don't understand what you mean in this comment. The error occurs in the already-compiled koa-static/index.js
file, not the user's TS code.