Package.json语法错误?
问题描述:
我试图运行npm install
,我得到这个:Package.json语法错误?
[email protected]:/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"
}
任何帮助,将不胜感激!
答
JSON似乎是有效的(我通过在线解析器运行它)。我跑了相同package.json
windows下,得到了以下的输出:
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 [email protected]
3 info using [email protected]
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错误。
答
出于某种原因,错误的代码在我的package.json中。不知道它是如何到达那里,但我绝对没有把它放在那里。我重新安装了一切,现在它已经修复并且正确的代码现在在那里。
我可以在http://jsonlint.com/看到,这是一个有效的json内容 –
@MadhavanKumar是的,我检查了它,它是有效的,所以我不知道什么是错的。 – KriiV
@KriiV尝试'npm install --loglevel愚蠢'或更好'--loglevel verbose'(愚蠢是非常疯狂的)看到你的错误的更多细节 – Molda