以下是我的同事npm whoami
时收到的错误消息:
npm ERR! Darwin 14.5.0
npm ERR! argv "/Users/dariusgatlin/.nvm/versions/node/v4.4.7/bin/node" "/Users/dariusgatlin/.nvm/versions/node/v4.4.7/bin/npm" "whoami"
npm ERR! node v4.4.7
npm ERR! npm v2.15.8
npm ERR! The header content contains invalid characters
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /Users/dariusgatlin/WebstormProjects/account-service/npm-debug.log
npm login
有效,但npm install
会产生相同的错误消息
这是npm-debug日志
17 http request GET https://registry.npmjs.org/-/whoami
18 verbose stack TypeError: The header content contains invalid characters
18 verbose stack at ClientRequest.OutgoingMessage.setHeader (_http_outgoing.js:351:13)
18 verbose stack at new ClientRequest (_http_client.js:79:14)
18 verbose stack at Object.exports.request (http.js:31:10)
18 verbose stack at Object.socket.once.exports.request (https.js:182:15)
18 verbose stack at Request.start (/Users/dariusgatlin/.nvm/versions/node/v4.4.7/lib/node_modules/npm/node_modules/request/request.js:753:32)
18 verbose stack at Request.end (/Users/dariusgatlin/.nvm/versions/node/v4.4.7/lib/node_modules/npm/node_modules/request/request.js:1418:10)
18 verbose stack at end (/Users/dariusgatlin/.nvm/versions/node/v4.4.7/lib/node_modules/npm/node_modules/request/request.js:580:14)
18 verbose stack at Immediate._onImmediate (/Users/dariusgatlin/.nvm/versions/node/v4.4.7/lib/node_modules/npm/node_modules/request/request.js:594:7)
18 verbose stack at processImmediate [as _immediateCallback] (timers.js:383:17)
19 verbose cwd /Users/dariusgatlin/WebstormProjects/account-service
20 error Darwin 14.5.0
21 error argv "/Users/dariusgatlin/.nvm/versions/node/v4.4.7/bin/node" "/Users/dariusgatlin/.nvm/versions/node/v4.4.7/bin/npm" "whoami"
22 error node v4.4.7
23 error npm v2.15.8
24 error The header content contains invalid characters
25 error If you need help, you may report this error at:
25 error <https://github.com/npm/npm/issues>
26 verbose exit [ 1, true ]
尝试的调试步骤包括:
关于错误的可能相关说明:http://www.alexkras.com/typeerror-the-header-content-contains-invalid-characters/
答案 0 :(得分:1)
我的建议是使用open ~/.npmrc
检查您的注册表值。
我自己也有同样的问题。事实证明,我的~/.npmrc
文件中的值不正确。编辑您的值,清除您的npm缓存和node_modules文件夹,然后再次运行npm install。
最初:
registry=https://registry.npmjs.org/
@company:registry=https://your-repo-key-address/dev/registry/
//your-repo-key-address/dev/registry/:_authToken="abc"
修正:
registry=https://registry.npmjs.org/
@company:registry=https://your-repo-key-address/dev/registry/
//your-repo-value-address/dev/registry/:_authToken="abc"
这些行分别是npm的默认注册地址,贵公司的私人注册地址,以及要传递给密钥地址的值。
我通过与注册管理团队密切合作并让他们转发我的注册地址来解决这个问题。
我希望这有帮助!