Can't install any package with node npm

前提是你 提交于 2019-11-27 11:26:23
npm install <packagename> --registry http://registry.npmjs.org/

Try specifying the registry with the install command. Solved my problem.

I had this issue, and doing npm cache clean solved it.

For future reference, this can also happen if npm is down. That's how I found this question. Wish the first npm task was a server status check so there was a clearer error message.

This is to do with SSL for some reason. If you set the registry to be plain http then it should work. You can set it to always be this via:

npm config set registry http://registry.npmjs.org/

or as jairaj said, you can supply it in the command line.

1.>Go to your this location

C:\Users\{your user name or ID}

2.> open .npmrc & Remove all content from .npmrc file.

3.>reopen your new command prompt

4.>again run the code , will work.

Jesus

Translated:

It happened the same to me and in my case in particular was because the package.json was wrong. example:

{
   "name": "app",
   "version": "0.0.0",
   "description": "any description",
   "main": "index.js",
   "author": "me", ->wrong
}

The last comma was left over and it gave me error any instalacción with npm in this proyect

then:

{
   "name": "app",
   "version": "0.0.0",
   "description": "any description",
   "main": "index.js",
   "author": "me"
}

I hope it will help.

The problem is with ssl

you should use sudo. Follow below method to resolve the issue.

if you are getting this issue enter sudo npm config set strict-ssl false password: Enter current username password

then now run all ur command wit sudo sudo npm npm install -g underscore password: Enter current username password

Even after if your getting error. Your proxy will be problem. few corporate proxy will be blocked, so you should use wifi or open network to fix this issue.

Try:

npm install underscore

:)

There is no unserscore package in npm registry.

This worked for me (not using proxy):

  1. set registry mirror for npm..

    npm config set registry http://skimdb.npmjs.com/registry

found mirror from docs:https://docs.npmjs.com/misc/registry

  1. after this try npm install if it works then try to install whatever you want otherwise follow below steps as well

3.npm install -g handlebar //i did because it was showing error in npm log but you can skip

4.after that try to set again official registry

npm config set registry http://registry.npmjs.org

5.now try to install whatever package you want :-)

If anyone is specifically getting Unexpected token <, and your package.json is fine, check your npm-shrinkwrap.json file! I had unresolved merge issues in mine, and fixing that resolved everything.

Following on from LAXIT KUMAR's recommendation, we've found that at times the registry URL can get corrupted, not sure how this is happening, however to cure, just reset it:

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

The 404 disappeared as it was going to the correct location again.

I also had problem in Ubuntu 15.10 while installing gulp-preetify.

The problem was:

  1. Registry returned 404 for GET on http://registry.npmjs.org/gulp-preetify

  2. I tried by using npm install gulp-preetify but it didn't worked.

  3. Again i tried using: npm i gulp-preetify and it just got installed.

I cannot guarantee that it will solve your problem but it won't harm with a single try.

If you're unlucky enough to be switching back and forth from a network behind a proxy and a network NOT behind a proxy, you may have forgotten that your NPM config is set to expect a proxy.

For me, I had to open up ~/.npmrc and comment out my proxy settings (while at home) and vice versa while at work (behind the proxy).

Adding a -g to the end of my install fixed this for me. ex: npm install uglify-js -g

This means the npm command is getting an HTML document instead of whatever format is is looking for. In my case, I was using sinopia. When I no longer wanted to use it, I accidentally used this command to reset the registry:

npm config set registry https://www.npmjs.com/

which was wrong, and it should have been the command already mentioned here. Read this if none of the answers solve this problem, and you can probably figure out where the incorrect URL is present and clear it off, and set the registry to the correct URL:

npm config set registry https://registry.npmjs.org
Sunitha Premakumaran

There is a possibility that your package.json is causing this.

Parse your package.json to find the unexpected token

or

Delete your package.json file and create one through

npm install 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!