Discuss / JavaScript / 转码不成功

转码不成功

Topic source

koaTest.

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('./koaTest.js');

package.json

{
    "name": "hello-koa2",
    "version": "1.0.0",
    "description": "Hello Koa 2 example with async",
    "main": "start.js",
    "scripts": {
        "start": "node start.js"
    },
    "keywords": [
        "koa",
        "async"
    ],
    "author": "zachrey",
    "license": "Apache-2.0",
    "repository": {
        "type": "git",
        "url": "https://github.com/michaelliao/learn-javascript.git"
    },
    "dependencies": {
        "babel-core": "6.13.2",
        "babel-polyfill": "6.13.0",
        "babel-preset-es2015-node6": "0.3.0",
        "babel-preset-stage-3": "6.5.0",
        "koa": "2.0.0"
    }
}

错误信息:

app.use((() => {
          ^
SyntaxError: Unexpected token )
    at Module._compile (module.js:439:25)
    at loader (D:\nodejsWorkspace\LXFTeacher\node_modules\babel-core\node_modules\babel-register\lib\node.js:146:5)
    at Object.require.extensions.(anonymous function) [as .js] (D:\nodejsWorkspace\LXFTeacher\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> (D:\nodejsWorkspace\LXFTeacher\start.js:7:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

在工程目录下,执行过npm install

廖雪峰

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

先看Node版本

Mo1Jian

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

VS Code需要的配置文件中配置修改了吗?


  • 1

Reply