当我运行npm version
时,它会抛出一些错误。这是整个npm-debug.log文件:
0 info it worked if it ends with ok
1 verbose cli [ 'node', '/usr/local/bin/npm', 'version' ]
2 info using npm@2.1.17
3 info using node@v0.10.35
4 verbose node symlink /usr/local/bin/node
5 verbose config Skipping project config: /Users/realph/.npmrc. (matches userconfig)
6 error version Bad package.json data undefined
7 verbose type unexpected_token
8 verbose stack SyntaxError: Unexpected token u
8 verbose stack at Object.parse (native)
8 verbose stack at /usr/local/lib/node_modules/npm/lib/version.js:36:19
8 verbose stack at evalmachine.<anonymous>:208:20
8 verbose stack at OpenReq.Req.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:141:5)
8 verbose stack at OpenReq.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:61:22)
8 verbose stack at Object.oncomplete (evalmachine.<anonymous>:108:15)
9 verbose cwd /Users/realph
10 error Darwin 14.0.0
11 error argv "node" "/usr/local/bin/npm" "version"
12 error node v0.10.35
13 error npm v2.1.17
14 error Unexpected token u
15 error If you need help, you may report this error at:
15 error <http://github.com/npm/npm/issues>
16 verbose exit [ 1, true ]
不确定是否与将shell更改为zsh有关。
感谢任何帮助。提前谢谢!
答案 0 :(得分:0)
这里有两个问题。
其中一个问题是npm
的最新版本中存在一个错误,如果npm version
缺失或包含无效数据,则package.json
会出错。 https://github.com/npm/npm/issues/7056应该使用npm@2.2.0
修正,latest
将在今天晚些时候正式package.json
。您可以按照https://github.com/npm/npm/wiki/Troubleshooting#try-the-latest-stable-version-of-npm
第二个问题是无法解析您的Bad package.json data undefined
7 verbose type unexpected_token
8 verbose stack SyntaxError: Unexpected token u
文件 - 请查看上面的错误消息:
{{1}}
您应该检查package.json文件以查看它是否有效JSON http://www.json.org/(这是javascript的严格子集,标识符名称必须是双引号等)。您可以通过http://jsonlint.com/
处的验证程序运行它