2017-07-26 79 views
0

我用这个NPM脚本从package.json文件:如何使用模块CLI通过npm进行调试?

"scripts": { 
    "build": "rollup --config", 
    "build-debug": "node --nolazy --inspect-brk=5858 rollup --config" 
} 

汇总是本地安装rollup.js library的CLI和node_modules/.bin

所以可当我执行npm run build它很好地工作。 现在我想用VSCode调试器执行这个命令。

所以我创建了launch.json文件与此配置:

"configurations": [ 
    { 
     "type": "node", 
     "request": "launch", 
     "name": "Build", 
     "cwd": "${workspaceRoot}", 
     "runtimeExecutable": "npm", 
     "windows": { 
      "runtimeExecutable": "npm.cmd" 
     }, 
     "runtimeArgs": [ 
      "run", 
      "build-debug" 
     ], 
     "port": 5858 
    } 
] 

但调试失败

Debugging with inspector protocol because a runtime executable is set.
npm.cmd run build-debug
Debugger listening on ws://127.0.0.1:5858/e0210d85-ee1d-4895-a67f-a23581725b31
Debugger attached.
module.js:487
throw err;

Error: Cannot find module 'd:\Temp\myproject\rollup'

如果我使用的汇总路径,我有一个语法错误:

"scripts": { 
    "build-debug": "node --nolazy --inspect-brk=5858 node_modules/.bin/rollup --config" 
} 

Debugging with inspector protocol because a runtime executable is set.
npm.cmd run build-debug
Debugger listening on ws://127.0.0.1:5858/c43fe903-b54d-4804-84d2-37d3c98b40e2
Debugger attached.
d:\Temp\myproject\node_modules\.bin\rollup:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\,/,g')")

SyntaxError: missing) after argument list

任何想法或建议吗?

回答

0

你可以这样做。此处,vscode在调试运行汇总中启动节点,并使用您的工作目录中的任何配置:

"configurations": [ 
    { 
     "type": "node", 
     "request": "launch", 
     "name": "Launch Program", 
     "program": "${workspaceFolder}/node_modules/rollup/bin/rollup", 
     "args": [ 
      "-c" 
     ] 
    } 
]