Note: If you are installing locally in a specific location then first go to that directory using command and then run above command. If you are not inside that directory and giving only path in command that will not work.
If you get package.json missing error then run below command before installing package locally
C:\Sample\Example1> npm init
above command will create package.json file. No need to provide any data. just hit enter.
Note: If you are behind a firewall then you may need to set a proxy.
which will take priority over the default one (http://registry.npmjs.org/). You can delete this line in the file or use the default registry like that:
If you have access to the registry but the error is still occurred nothing mentioned above wouldn't work. I noted that this problem is only applicable for local project's installation (i.e. if you use -g to global install everything is working fine).
What's resolved the problem for me: just remove an entry regarding a package you're going to install from a project's package.json file. After that next call to npm will work and install the package successfully.
Most likely to be npm registry cannot be reached by npm. Check npm proxy configuration
I had exactly the same issue on Windows Server 2008 R2. I suspected Internet Explorer's Enhanced Security Configuration at first but after turning that off with no success the issue turned out to be that npm was not configured to use my corporate proxy connection to the internet.
It turns out that npm does not use the proxy settings in effect via Internet Options > Connections tab > LAN settings where the server is set to 'Automatically detect settings'. Being set to automatically detect settings does not guarantee that a proxy is indeed being used, it just means that Windows will automatically configure proxy settings for Internet Explorer if it finds a special'wpad.dat' file at http://wpad.[yourdomain.com]/wpad.dat.
You can test whether a wpad.dat file is in use in your organisation by typing the following into a web browser.
http://wpad.[yourcompany.domain]/wpad.dat
If no file is available then it is likely you are not using an organization-wide proxy. If one does get returned to the browser then...
Toward the bottom of this file, you should see a line saying
PROXY <host:port>;
It might be repeated if you have multiple proxies available. The host and port are needed in order to tell npm to use the proxy settings like so:
npm config set proxy http://[host]:[port]
and
npm config set https-proxy http://[host]:[port]
For example if your proxy is at my.proxy.com on port 8080 then the npm commands would be:
npm config set proxy http://my.proxy.com:8080
npm config set https-proxy http://my.proxy.com:8080
Once I had told npm which proxy to use all started working in I was able to run the install commands without a problem.
Thanks to the following post for help with the wpad file discovery.
I had the same effect creating a react app with PhpStorm. And then at the end it just says done. Running the same command in the terminal gave me detailed errors. The project folder I've created was named react which seems to be a no-go.
In some rarer occasions, check that the project can be built using regular npm commands. I ran into one that is configured to work with bower, so bower install <github_url> works while npm install <github_url> gives that unhelpful cryptic error message on all platforms...
While installing the Angular Command line tool (CLI), If you are getting Rollback Error then it may be occurring due to your network is connected with your Client Network or your Company Network where you are working on.
So Please try to install CLI in your public network (or Your Mobile's hotspot Network) then you would definitely get CLI installed.
Solution:
The default value of ‘proxy’ and ‘https-proxy’ key of npm config is NULL. After doing some more R & D then I tried to set the proxy setting value to above key (this solution works in my scenario).
Also, the same proxy settings need to be applied in IE browser Internet Settings >> Settings >> LAN settings.
Conclusion:
In corporate/some environment the proxy is a somewhat mandatory setting otherwise npm install will not work.
You can resolve the issue by looking if your network has any proxies, that is prohibiting the download process. My company's network had a firewall enabled, which was causing the issue for me. So I had to switch to an un-secure network (probably a hotspot from your mobile network), and that worked for me.
npm config set proxy http://yourproxyurl.com:8080 (you need to enter your or your company proxy URL and 8080 should be replaced by your proxy port)
npm config set https-proxy http://yourproxyurl.com:8080
Mine was due to McAfee firewall.
It is set to Ask mode, so should have popped up a prompt to ask for internet connection, but it didn't!
Going into McAfee and (temporarily!) disabling the firewall allowed me to install.
I've already had the proxies set as described above and it was working until today. Then it turned out that now I need "http://" in front of my proxy address: "http://{proxyURL}:{proxyPort}". Then it finally worked.
Struggled with this issue for some time before figuring it out.
I'm using High Sierra (10.13.6)
Uninstalled and re-installed node and nvm multiple times - using the installer.pkg, HomeBrew, and then using the command line. IMO, the command line works the best.
I followed these steps:
1. Ran npm config ls -l
2. Checked that the value for globalconfig was $<installpath>/.nvm/versions/node/v12.16.3/etc/npmrc But when I tried to get to this path in the Terminal, it gave me No such file or directory
So I
3. created the folder etc, created the npmrc file and added this line in it.
registry = "https://registry.npmjs.org/"
I do not have the ABC0 file in my $HOME
Then
4. I re-ran the npm install command.
Note that this still threw the rollbackFailedOptional: verb npm-session error, but this time it completed, though with a different error.
You could try these steps and see if it works.
For those who are curious, it threw a Response timeout while trying to fetch https://registry.npmjs.org/<package> (over 30000ms) error, so I added the timeout = "60000" to the /etc/npmrc file (as found on another Stackoverflow thread), and tried again. This worked for me.
Download the updated nodejs setup from their website
Install it in any drive but not on previously installed drive like if you installed in C drive then install in D,S,G Drive
Run your npm command it will completely work fine
For people that use yarn package. Just go to the project folder that you are having this issue with. Let's say the project's folder name is chatApp:
cd chatApp
And then if you have already done yarn or yarn install then delete the node_modules folder and run the below command or if you haven't done yarn install, only run the blow command:
yarn cache clean
Once yarn has successfully cleaned the cache, run the below command:
yarn config set registry https://registry.npmjs.org/