Molunerfinn / vue-koa-demo

:beginner:A simple full stack demo(CSR & SSR & Docker Support) written by Vue2 & Koa2(Koa1 verson also completed)
MIT License
756 stars 166 forks source link

vscode调试时,项目语法报错 #22

Closed huoyanwuzhe629 closed 7 years ago

huoyanwuzhe629 commented 7 years ago

在使用vscode对koa server部分进行调试时,启动报错,

SyntaxError: Unexpected token function
/Users/xiongsheng/personal_project/Github/vue-koa-demo/node_modules/koa-jwt/lib/index.js:17
    const middleware = async function jwt(ctx, next) {
                             ^^^^^^^^
SyntaxError: Unexpected token function

我的launch.json配置如下

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/server-entry.js",
            "sourceMaps": true,
            "runtimeExecutable": null,
            "runtimeArgs": [
            ],
            "outFiles": []
        }
    ]
}

想知道launch.json该如何配置

Molunerfinn commented 7 years ago

这个报错是不是因为你的node版本并没有在7.6之上呢?async、await的语法需要在node7.6以上才能实现。 我的launch.json配置如下:

{
  // Use IntelliSense to learn about possible Node.js debug attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [

    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${file}"
    },
    {
      "type": "node",
      "request": "attach",
      "name": "Attach to Port",
      "address": "localhost",
      "port": 9229,
      "restart": true
    }
  ]
}

需要先用nodemon运行项目再进行调试,因为是attach to port的方式。注意看我package.json里的npm run server 跑的命令。

huoyanwuzhe629 commented 7 years ago

node 版本7.6.0,launch.json使用你上面的配置,启动调试,ide报错: "无法启动程序”/Users/xiongsheng/personal_project/Github/vue-koa-demo/.vscode/launch.json“;设置”outFiles“属性可能会有帮助" npm run server执行是成功的

Molunerfinn commented 7 years ago

看了一下是vscode更新导致的。另外由于它的更新现在可以直接配置nodemon调试了。所以我更新了一下调试的配置,直接通过debug来启动server端就行了。注意在debug的时候需要选择一下你使用的配置,是从nodemon启动的: image

{
      "type": "node",
      "request": "launch",
      "name": "nodemon",
      "runtimeExecutable": "nodemon",
      "program": "${workspaceFolder}/server-entry.js",
      "restart": true,
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    }
huoyanwuzhe629 commented 7 years ago

哈哈哈,总算搞定了,非常感谢