Discuss / JavaScript / 运行失败了/(ㄒoㄒ)/~~

运行失败了/(ㄒoㄒ)/~~

Topic source

撸倩倩

#1 Created at ... [Delete] [Delete and Lock User]

报语法错误:

/home/keke/scripts/learn_nodejs/hello-koa/app.js:5
app.use((() => {
          ^
SyntaxError: Unexpected token )
    at Module._compile (module.js:439:25)
    at loader (/home/keke/scripts/learn_nodejs/hello-koa/node_modules/babel-core/node_modules/babel-register/lib/node.js:146:5)
    at Object.require.extensions.(anonymous function) [as .js] (/home/keke/scripts/learn_nodejs/hello-koa/node_modules/babel-core/node_modules/babel-register/lib/node.js:156:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/keke/scripts/learn_nodejs/hello-koa/start.js:5:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

app.js:

const Koa = require('koa');
const app= new Koa();
app.use(async (ctx,next)=>{
    await next();
    ctx.response.type="text/html";
    ctx.response.body='<h1>Hello,koa2!</h1>';
})
app.listen(3000);
console.log('app started at port 3000...');

start.js:

var register = require('babel-core/register');
register({
    presets:['stage-3']
});
require('./app.js');

撸倩倩

#2 Created at ... [Delete] [Delete and Lock User]

解决了,node.js版本不对


  • 1

Reply