Package.json语法错误?

时间:2015-10-18 11:19:27

标签: json node.js npm

我试图运行npm install而我得到了这个:

root@WF-DEV1:/var/www/laravel# npm install                                                                                                                              
npm ERR! install Couldn't read dependencies                                                                                                                             
npm ERR! Failed to parse json                                                                                                                                           
npm ERR! Unexpected token }                                                                                                                                             
npm ERR! File: /var/www/laravel/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  

这是我的package.json文件:

{
  "name": "bootstrap-tagsinput",
  "title": "Bootstrap Tags Input",
  "version": "0.5.0",
  "description": "jQuery plugin providing a Twitter Bootstrap user interface for managing tags.",
  "scripts": {
    "test": "karma start --single-run --no-auto-watch"
  },
  "main" : "dist/bootstrap-tagsinput.js",
  "repository": {
    "type": "git",
    "url": "git://github.com/timschlechter/bootstrap-tagsinput.git"
  },
  "author": "Tim Schlechter",
  "contributors": [{
      "name": "Luckner Jr Jean-Baptiste"
   }],
  "license": "MIT",
  "homepage": "http://timschlechter.github.io/bootstrap-tagsinput/examples/",
  "download": "http://timschlechter.github.io/bootstrap-tagsinput/build/bootstrap-tagsinput.zip",
  "keywords": [
    "tags",
    "bootstrap",
    "input",
    "select",
    "form"
  ],
  "readmeFilename": "README.md",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-cli": "~0.1.13",
    "grunt-contrib-copy": "~0.5.0",
    "grunt-contrib-uglify": "~0.2.2",
    "grunt-jquerymanifest": "~0.1.4",
    "grunt-zip": "~0.15.0",
    "karma": "~0.12.19",
    "phantomjs": "~1.9.7-15",
    "karma-phantomjs-launcher": "~0.1.3",
    "karma-jasmine": "~0.1.5",
    "grunt-karma": "~0.8.3",
    "bower": "~1.3.8",
    "grunt-bower-task": "~0.4.0"
  },
  "banner": "/*\n * <%= pkg.name %> v<%= pkg.version %> by <%= pkg.author %>\n * <%= pkg.license.url %>\n */\n"
}

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:0)

JSON似乎有效(我通过在线解析器运行它)。我在Windows下运行了相同的package.json并获得了以下输出:

D:\workspace\deleteme>npm install
npm ERR! install Couldn't read dependencies
npm ERR! Windows_NT 10.0.10240
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v4.1.1
npm ERR! npm  v2.14.4
npm ERR! file D:\workspace\deleteme\package.json
npm ERR! code EJSONPARSE

npm ERR! Failed to parse json
npm ERR! Unexpected token '<' at 1:1
npm ERR! <!DOCTYPE html>
npm ERR! ^
npm ERR! File: D:\workspace\deleteme\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! Please include the following file with any support request:
npm ERR!     D:\workspace\deleteme\npm-debug.log

npm-debug.log以:

开头
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install' ]
2 info using npm@2.14.4
3 info using node@v4.1.1
4 verbose readDependencies loading dependencies from D:\workspace\deleteme\package.json
5 error install Couldn't read dependencies
6 verbose stack Error: Failed to parse json
6 verbose stack Unexpected token '<' at 1:1
6 verbose stack <!DOCTYPE html>
6 verbose stack ^
6 verbose stack     at parseError (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:379:11)
6 verbose stack     at parseJson (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:68:23)
6 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:48:5
6 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:76:16
6 verbose stack     at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
7 verbose cwd D:\workspace\deleteme

所以,在预感中,我将您的devDependencies更改为dependencies,这样就有效了。所以我没有一个坚定的答案,但是你的文件中肯定存在npm存在问题 - 它只是一个JSON错误。

答案 1 :(得分:0)

出于某种原因,我的package.json中存在错误的代码。不知道它是如何到达那里但我绝对没有把它放在那里。我重新安装了一切,它现在已经修复,正确的代码就在那里。