Reputation: 20212
I'm getting a harmony error when trying to run Koa.
Here is the error after I ran my mocha tests, I get this error at the end:
MacBook-Pro$ mocha test
...projects/search-api/node_modules/koa/lib/application.js:179
function *respond(next) {
^
SyntaxError: Unexpected token *
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
Here's my server.js
'use strict';
var supertestKoa = require('supertest-koa-agent');
var app = module.exports = require('koa')(),
port = process.env.PORT || 3000;
supertestKoa(app);
app.listen(port, function(){
console.log('Koa app is listening on port' + port);
});
Let me know if you need anything else from me to help troubleshoot this.
Upvotes: 2
Views: 1748
Reputation: 1296
This is because of function *
in application.js not your node file. function *
is a generator function in ES6 (ES2015) http://wiki.ecmascript.org/doku.php?id=harmony%3agenerators. This is the next version of javascript that not all version of browsers/node.js support yet.
There are a couple options here you can transpile that file back to ES5 so that browsers/node.js can understand it. You can also use something like babel to transpile your code back to ES5. You can also set the --harmony
flag in node which will allow node to understand and utilize the generator function.
Upvotes: 0
Reputation: 9437
It's failing on the generator function*
syntax. Here are a few options to get around this:
node --harmony path/to/mocha
.Upvotes: 3