Javascript 安装时使用grunt启动项目时出错

Javascript 安装时使用grunt启动项目时出错,javascript,node.js,gruntjs,Javascript,Node.js,Gruntjs,我正在尝试使用gruntjs启动一个新项目 我有这个项目结构: grunt-test (dir) |_ index.html |_ package.json |_ Gruntfile.js |_ assets (dir) |_ _js (dir) |_ scripts.js |_ _sass (dir) |_ style.sass 我已经安装了nodejs和grunt 所以,当我转到project文件夹并在终端上使用以下命令行时:npm

我正在尝试使用gruntjs启动一个新项目

我有这个项目结构:

grunt-test (dir)
  |_ index.html
  |_ package.json
  |_ Gruntfile.js
  |_ assets (dir)
    |_ _js (dir)
      |_ scripts.js
    |_ _sass (dir)
      |_ style.sass
我已经安装了nodejs和grunt

所以,当我转到project文件夹并在终端上使用以下命令行时:
npm install grunt--save dev

它会返回所有这些错误:

npm ERR! Failed to parse json
npm ERR! Unexpected end of input
npm ERR! File: /Applications/XAMPP/xamppfiles/htdocs/grunt-test/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! 
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! System Darwin 11.4.2
npm ERR! command "node" "/usr/local/bin/npm" "install" "grunt" "--save-dev"
npm ERR! cwd /Applications/XAMPP/xamppfiles/htdocs/grunt-test
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! file /Applications/XAMPP/xamppfiles/htdocs/grunt-test/package.json
npm ERR! code EJSONPARSE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Applications/XAMPP/xamppfiles/htdocs/grunt-test/npm-debug.log
npm ERR! not ok code 0

我已经尝试安装了一段时间,但没有任何成功。我不知道我做错了什么。我遵循gruntjs文档的所有说明。有人能帮我吗?

您的
包。json
不是有效的
json
。您可以在
package.json
文件中添加这些命令作为
devdependency
,而不是键入命令,然后使用
npm install
package.json
文件安装包。您可以使用下面的选项

{
    "name": "Project Name",
    "version": "1.0.0",
    "devDependencies": {
        "grunt": "0.4.4",
        "grunt-cli": "0.1.13"
    }
}

如果未找到
grunt
,请运行
npm install grunt cli-g
。将显示消息。

在您的package.json中,字符串包含在单引号(')中,这将使其成为无效的json数据。JSON希望字符串包含在双引号(“”)中.

你能给我们看看你的package.json吗?我该怎么办?每次我创建一个新项目时,我都必须在package.json上创建并添加一些行,然后才能使用终端?我的错。请为json道具添加引号。更新了答案。图像看起来与前一个相同。你确定错误相同吗?前一个是返回它:npm ERR!意外标记“…现在它返回以下内容:npm ERR!意外标记”您需要将整个字符串用双引号括起来。谁知道呢!只需使用更新的文件。它可以工作。在Windows中测试。