我正在尝试在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 "$0" | 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 "$0" | 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。任何想法如何解决这个问题?
edit2:
在根据文章编辑了启动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。但是它似乎并没有在断点处停止。
答案 0 :(得分:1)
您所引用的文章提到:
我可以通过将行更改为:
"dev-debug": "node_modules/.bin/nuxt --inspect"
检查是否足够。
类似地,nuxt/nuxt.js
issue 2528包括:
通过关注该文章,目前可以使其正常工作。
{
"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"
用于Windows平台的正确命令应如下所示
"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”包括:
如果我改为指向
node_modules/serverless/bin
,则说明一切正常:"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 */
在Google Chrome的上下文中,seen here也支持debugger命令作为在代码中设置断点的工具。
另请参见“ how to disable eslint rules when you need to”。