【发布时间】:2016-03-25 18:26:24
【问题描述】:
我正在尝试使用 Visual Studio Code、Node.js 和 Grunt,但遇到了问题。本质上,我似乎无法说服 VS Code 从 npm 放置的本地 node_modules\.bin 位置运行 grunt。如果我在全球范围内安装grunt 和grunt-cli,一切正常,但就个人而言,我不明白为什么我必须这样做。
我有一个如下所示的package.json 文件:
{
"version": "1.0.0",
"name": "VSCODETEST",
"private": true,
"devDependencies": {
"grunt": "~0.4.5",
"grunt-cli": "~1.1.0",
"typescript": "~1.8.9",
"grunt-typescript": "~0.8.0"
},
"dependencies": {
"jquery": "~2.2.2",
"bootstrap": "4.0.0-alpha.2"
}
}
运行npm install 下载依赖层次结构。
我在我的gruntfile.js 中定义了各种任务,在我的项目的根目录中,这个任务文件在.vscode\tasks.json 中:
{
"version": "0.1.0",
"command": "grunt",
"isShellCommand": true,
"tasks": []
}
我知道这行得通,因为在全局安装工具后...
npm install -g grunt grunt-cli
... VS Code 会自动选择 gruntfile 中的任务并在 UI 中显示给我。
但是,如果我不全局安装它们(或者我卸载它们,全局),它会给我这个错误:
'grunt' is not recognized as an internal or external command,
operable program or batch file.
显然,它在其路径中找不到grunt,所以我尝试通过修改任务文件来解决这个问题...
{
"version": "0.1.0",
"command": "${workspaceRoot}\\node_modules\\.bin\\grunt",
"isShellCommand": true,
"tasks": []
}
这解决了错误,但我不再列出任何任务 - 我只得到“未找到任务”
如何在 VS Code 用来查找其工具的 PATH 中包含 node_modules\.bin 或以其他方式解决此问题?
【问题讨论】:
标签: node.js gruntjs npm visual-studio-code