我有一个空文件夹,我在其中创建了一个package.json
文件,其中包含:
{
"name":"sample project",
"version":"0.0.1",
"title":"My grunt App",
"homepage":"http://gruntjs.com"
}
稍后在同一文件夹中,我正在尝试运行此命令:
npm install grunt --save-dev
但是我收到这样的错误:根本无法安装grunt
D:\grunt2>npm install grunt --save-dev
npm ERR! Error: Invalid name: "sample project"
npm ERR! at ensureValidName (C:\Program Files (x86)\nodejs\node_modules\npm\
node_modules\read-package-json\node_modules\normalize-package-data\lib\fixer.js:
300:15)
npm ERR! at Object.module.exports.fixNameField (C:\Program Files (x86)\nodej
s\node_modules\npm\node_modules\read-package-json\node_modules\normalize-package
-data\lib\fixer.js:204:5)
npm ERR! at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\read
-package-json\node_modules\normalize-package-data\lib\normalize.js:30:38
npm ERR! at Array.forEach (native)
npm ERR! at normalize (C:\Program Files (x86)\nodejs\node_modules\npm\node_m
odules\read-package-json\node_modules\normalize-package-data\lib\normalize.js:29
:15)
npm ERR! at final (C:\Program Files (x86)\nodejs\node_modules\npm\node_modul
es\read-package-json\read-json.js:342:33)
npm ERR! at then (C:\Program Files (x86)\nodejs\node_modules\npm\node_module
s\read-package-json\read-json.js:126:33)
npm ERR! at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\read
-package-json\read-json.js:316:48
npm ERR! at fs.js:207:20
npm ERR! at OpenReq.Req.done (C:\Program Files (x86)\nodejs\node_modules\npm
\node_modules\graceful-fs\graceful-fs.js:144:5)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/npm/npm/issues>
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program File
s (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "grunt" "--save-d
ev"
npm ERR! cwd D:\grunt2
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.9
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! D:\grunt2\npm-debug.log
npm ERR! not ok code 0
无法理解此问题。有人帮我吗?
实际上我正在尝试重现本教程:http://www.anujgakhar.com/2013/02/28/writing-a-simple-grunt-task-using-gruntjs/
答案 0 :(得分:6)
不要在项目名称中使用空格。例如,更改为sample-project
。
(这是第一个错误行,顺便说一下:Error: Invalid name: "sample project"
)
答案 1 :(得分:2)
package.json中的name
- 字段无效,正如错误所说的那样。删除空格(使用点或短划线),它应该没问题。 According to the developers这是name will be used in urls, folders etc.