我试图用npm安装typedoc,但是看到以下错误:
npm ERR! Invalid name: "@types/handlebars"
然后我尝试通过以下方式直接安装@ types / handlebars:
npm install @types/handlebars
同样的错误消息再次出现。当我尝试通过运行来查看包信息时:
npm info @types/handlebars
我可以正确查看信息。我还应该检查什么来解决这个问题? 我在OSX 10.10.5上使用节点v4.8.3和npm v2.15.11。
以下是来自npm-debug.log的堆栈跟踪:
58 verbose etag https://registry.npmjs.org/@types%2fhandlebars from cache
59 verbose get saving @types/handlebars to /Users/ycchen/.npm/registry.npmjs.org/_40types_252fhandlebars/.cache.json
60 verbose correctMkdir /Users/ycchen/.npm correctMkdir not in flight; initializing
61 silly addNameTag next cb for @types/handlebars with tag latest
62 silly addNamed @types/handlebars@4.0.33
63 verbose addNamed "4.0.33" is a plain semver version for @types/handlebars
64 verbose stack Error: Invalid name: "@types/handlebars"
64 verbose stack at ensureValidName (/usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/fixer.js:297:15)
64 verbose stack at Object.module.exports.fixNameField (/usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/fixer.js:201:5)
64 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/normalize.js:29:38
64 verbose stack at Array.forEach (native)
64 verbose stack at normalize (/usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/normalize.js:28:15)
64 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:349:5)
64 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:5)
64 verbose stack at ReadFileContext.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:295:20)
64 verbose stack at ReadFileContext.callback (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16)
64 verbose stack at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:303:13)
答案 0 :(得分:1)
我怀疑这与它实际获取类型的位置有关。 info命令有效,因为它必须查看官方的npm注册表。
要试用它,您可以覆盖特定范围的注册表(在本例中为@types)。例如:
npm config set @types:registry https://registry.npmjs.org/
这告诉npm总是直接从官方注册表获取@types范围的任何内容。
编辑:我从你编辑的问题中看到,npm确实试图从官方注册表中获取它,所以你可能希望获得最新的npm,因为你使用的版本已经过时了。你可以这样做:sudo npm cache clean
sudo npm install npm -g