Search code examples
node.jstypescriptnpmtypedoc

npm ERR! Invalid name: "@types/handlebars"


I was trying to install typedoc with npm, however seeing the following error:

npm ERR! Invalid name: "@types/handlebars"

I then tried to install @types/handlebars directly by:

npm install @types/handlebars

And the same error message shows up again. When I try to view package info by running:

npm info @types/handlebars

I can see the info correctly. What else should I check to tackle the problem? I am using node v4.8.3 and npm v2.15.11 on OSX 10.10.5.

Here are the stack trace from 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/[email protected]
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)

Solution

  • I suspect this has to do with where it is actually getting the types from. The info command works since it must be looking at official npm registry.

    To try it out you can override the registry for specific scopes (@types in this case). For example:

    npm config set @types:registry https://registry.npmjs.org/
    

    This tells npm to always get anything for the @types scope directly from the official registry.

    EDIT: I see from your edited question that npm does try to get it from the official registry so you might wish to get the latest npm since the version you are using is quite dated. You can do so by:

    sudo npm cache clean
    sudo npm install npm -g