语法错误设置 nuxt/vue 使用 vs 代码调试

Syntax error setting up nuxt/vue debugging with vs code

我正在尝试在 win 10 上的 vs 代码中设置 nuxt/vue 项目的调试。我正在使用 git-bash。我找到了 https://medium.com/@justin.ramel/nuxt-js-debugging-in-visual-studio-code-822ff9d51c77

按照说明,我已将 package.json 更改为

{
  "name": "nuxt4",
  "version": "1.0.0",
  "description": "My classy Nuxt.js project",
  "author": "hh",
  "private": true,
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "dev-debug": "node --inspect node_modules/.bin/nuxt",
    "generate": "nuxt generate"
  },
  "dependencies": {
    "cross-env": "^5.2.0",
    "glob": "^7.1.3",
    "nuxt": "^2.0.0",
    "vue2-google-maps": "^0.10.6",
    "vuetify": "^1.2.4",
    "vuex": "^3.0.1"
  },
  "devDependencies": {
    "nodemon": "^1.11.0",
    "stylus": "^0.54.5",
    "stylus-loader": "^3.0.2"
  }
}

Launch.json:

{
 "configurations": [
{
  "type": "node",
  "request": "attach",
  "name": "Attach to Nuxt",
  "port": 9229
  }
]

}

但是:

$ npm run dev-debug

> nuxt4@1.0.0 dev-debug E:\ENVS\js\nuxt4
> node --inspect=0.0.0.0 node_modules/.bin/nuxt

Debugger listening on ws://0.0.0.0:9229/4eda468d-39a4-4ddb-9a73-23e4fa60ed8e
For help, see: https://nodejs.org/en/docs/inspector
E:\ENVS\js\nuxt4\node_modules\.bin\nuxt:2
basedir=$(dirname "$(echo "[=13=]" | sed -e 's,\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at new Script (vm.js:83:7)
    at createScript (vm.js:267:10)
    at Object.runInThisContext (vm.js:319:10)
    at Module._compile (internal/modules/cjs/loader.js:684:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
    at executeUserCode (internal/bootstrap/node.js:342:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nuxt4@1.0.0 dev-debug: `node --inspect=0.0.0.0 node_modules/.bin/nuxt`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nuxt4@1.0.0 dev-debug script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

报错的nuxt文件是:

    #!/bin/sh
    basedir=$(dirname "$(echo "[=14=]" | sed -e 's,\,/,g')")

    case $(uname) in
        *CYGWIN*) basedir=$(cygpath -w "$basedir");;
    esac

    if [ -x "$basedir/node" ]; then
    "$basedir/node"  "$basedir/../nuxt/bin/nuxt.js" "$@"
    ret=$?
    else 
    node  "$basedir/../nuxt/bin/nuxt.js" "$@"
    ret=$?
    fi
    exit $ret

我怎样才能让它工作?

编辑:

我最终发现

"dev-debug": "node --inspect ./node_modules/nuxt/bin/nuxt",

让我克服了那个错误。但是我有一个新问题:当我尝试调试时,我得到:

看来我正在尝试 运行 package.json。知道如何解决这个问题吗?

编辑2:

编辑后推出json以下基于文章:

{
  "type": "node",
  "request": "launch",
  "name": "Launch via NPM",
  "runtimeExecutable": "npm",
  "runtimeArgs": [
    "run-script",
    "dev-debug"
  ],

  "program": "${workspaceFolder}\node_modules\.bin\nuxt",
  "args": [
    "invoke",
    "local",
    "-f",
    "<function-name>",
    "--data",
    "{}" // You can use this argument to pass data to the function to help with the debug
],
  // "program": "E:\ENVS\js\nuxt4\node_modules\.bin\nuxt",
  "port": 9229
}

我正在

有什么想法吗?

编辑:

更近一点 launch.json 更改为:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "npm run dev",
      "runtimeExecutable": "npm",
      "windows": {
        "runtimeExecutable": "npm.cmd"
      },
      "runtimeArgs": [
        "run",
        "dev-debug"
      ],
      "port": 9229
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceRoot}/start"
    },
    {
      "type": "node",
      "request": "attach",
      "name": "Attach to Port",
      "address": "localhost",
      "port": 9229
    }
  ]
}

我现在可以将调试器附加到 process.it 不过似乎没有在断点处停止。

您引用的文章提到:

I was able to get this to work by changing the line to:

"dev-debug": "node_modules/.bin/nuxt --inspect"

检查是否足够。

同样,nuxt/nuxt.js issue 2528包括:

currently got it working by following that article a little bit.

{
        "type": "node",
        "request": "launch",
        "name": "Launch via NPM",
        "runtimeExecutable": "npm",
        "runtimeArgs": [
          "run-script",
          "dev-debug"
        ],
        "port": 9229
      }

"dev-debug": "node --inspect node_modules/.bin/nuxt"

nuxt/nuxt.js issue 433还包括:

The correct command for windows platform should look like this

"dev-debug": "node --inspect node_modules/nuxt/bin/nuxt",

OP 提到:

"dev-debug": "node --inspect ./node_modules/nuxt/bin/nuxt",

关于错误消息“无法启动程序...设置'outFiles'属性可能有帮助”,问题“Cannot debug serverless application in Visual Studio Code”包括:

if I point at node_modules/serverless/bin instead, things work as expected:

"program": "${workspaceFolder}\node_modules\serverless\bin\serverless",

你在文章“Running and debugging AWS Lambda functions locally with the Serverless framework and VS Code”的评论中还有其他线索。


OP 指向 standard/standard issue 260 中说明的提示:

debugger // eslint-disable-line

or:

/* eslint-disable no-debugger */

此外 seen here,在 Google 的上下文中 Chrome 支持调试器命令作为在代码中设置断点的工具。
另见“how to disable eslint rules when you need to”。