Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
huoyanwuzhe629 opened this issue Oct 13, 2017 · 4 comments
Closed

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

huoyanwuzhe629 opened this issue Oct 13, 2017 · 4 comments

Comments

@huoyanwuzhe629
Copy link

在使用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
Copy link
Owner

这个报错是不是因为你的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
Copy link
Author

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

@Molunerfinn
Copy link
Owner

看了一下是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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants