2017-05-10 8 views
0
......\node_modules\koa\lib\response.js:47 
const { res } = this; 
    ^

SyntaxError: Unexpected token { 
    at exports.runInThisContext (vm.js:53:16) 
    at Module._compile (module.js:373:25) 
    at Object.Module._extensions..js (module.js:416:10) 
    at Module.load (module.js:343:32) 
    at Function.Module._load (module.js:300:12) 
    at Module.require (module.js:353:17) 
    at require (internal/module.js:12:17) 
    at Object.<anonymous> (......\node_modules\koa\lib\application.js:11:18) 
    at Module._compile (module.js:409:26) 
    at Object.Module._extensions..js (module.js:416:10) 

Wenn ich meine Koa-Demo starte, zeigt die Konsole dies an.
Knoten Version: V4.4.7
"Koa": "^ 2.2.0"
Hier ist meine entry.js:Koa Start Fehler

const Koa = require('koa'); 
const app = new Koa(); 

app.use(ctx => { 
    ctx.body = 'Hello Koa'; 
}); 

app.listen(3000); 

Nachdem ich {} in response.js entfernen: 47 und Kontext. js: 124

const res = this; 

alles läuft ok.I weiß nicht, warum.

Antwort

0

Da const res = this; nur konstante Variable res bedeuten entspricht dies aber const { res } = this; ist Gegenstand Destrukturierung (http://exploringjs.com/es6/ch_destructuring.html) es ist gleich const res = this.res; Also, wenn this hat nicht Eigentum res Sie Fehler erhalten werden.

+0

Danke :), ich verstehe. – Yufan