Mehran Khan
Mehran Khan

Reputation: 1165

npm ERR! code ERR_SOCKET_TIMEOUT on creating new project using ng new appname

Can somebody help me on this? i am getting following error:

Angular & Node version Installed

Angular CLI: 12.0.1
Node: 14.16.0
Package Manager: npm 7.11.2
OS: win32 x64
    D:\Learning\Angular>ng new working
    ? Would you like to add Angular routing? No
    ? Which stylesheet format would you like to use? CSS
    CREATE working/angular.json (3045 bytes)
    CREATE working/package.json (1069 bytes)
    CREATE working/README.md (997 bytes)
    CREATE working/tsconfig.json (783 bytes)
    CREATE working/.editorconfig (274 bytes)
    CREATE working/.gitignore (604 bytes)
    CREATE working/.browserslistrc (703 bytes)
    CREATE working/karma.conf.js (1424 bytes)
    CREATE working/tsconfig.app.json (287 bytes)
    CREATE working/tsconfig.spec.json (333 bytes)
    CREATE working/src/favicon.ico (948 bytes)
    CREATE working/src/index.html (293 bytes)
    CREATE working/src/main.ts (372 bytes)
    CREATE working/src/polyfills.ts (2820 bytes)
    CREATE working/src/styles.css (80 bytes)
    CREATE working/src/test.ts (743 bytes)
    CREATE working/src/assets/.gitkeep (0 bytes)
    CREATE working/src/environments/environment.prod.ts (51 bytes)
    CREATE working/src/environments/environment.ts (658 bytes)
    CREATE working/src/app/app.module.ts (314 bytes)
    CREATE working/src/app/app.component.html (23777 bytes)
    CREATE working/src/app/app.component.spec.ts (943 bytes)
    CREATE working/src/app/app.component.ts (211 bytes)
    CREATE working/src/app/app.component.css (0 bytes)
    / Installing packages (npm)...npm WARN deprecated [email protected]: Please see     https://github.com/lydell/urix#deprecated
    npm WARN deprecated [email protected]: this library is no longer supported
    npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
    npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
    npm WARN deprecated [email protected]: request has been deprecated, see         https://github.com/request/request/issues/3142
    npm ERR! code ERR_SOCKET_TIMEOUT
    npm ERR! errno ERR_SOCKET_TIMEOUT
    npm ERR! request to https://registry.npmjs.org/@angular/cli/-/cli-12.0.1.tgz failed, reason: Socket timeout

    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\username\AppData\Local\npm-cache\_logs\2021-05-23T07_57_24_639Z-debug.log
    × Package install failed, see above.
    The Schematic workflow failed. See above.

Upvotes: 69

Views: 168835

Answers (24)

Tushar Shahi
Tushar Shahi

Reputation: 20306

If the above answers do not work for you just try to upgrade node and in turn npm. I was using node v18.12.1 and npm v8.19.2, it did not work for me with any of the solutions. Started using node 20 and npm 10, it installed in seconds.

So maybe it is an issue with specific npm version, as going back to it also caused it to hangup.

Upvotes: 1

Sixteen
Sixteen

Reputation: 563

Node version: 20.2.0
npm version : 9.6.7
Internet provider: Starlink

In my case, the issue is related to my internet connection. With the evolution of the internet, npm now uses IPv6 addresses. Unfortunately, Starlink is not yet compatible with IPv6.

There is a solution that involves configuring npm to prioritize IPv4 addresses, which would solve the problem. However, I am unable to get this solution to work; it seems more suitable for Linux than for Windows.

node --dns-result-order=ipv4first

More information here:

(Tweet from node about IPv6) https://twitter.com/matteocollina/status/1640384245834055680

(Blog to configure ipv4first on Linux) https://blog.nem.ec/code-snippets/npm-install-on-ipv4-only-network/)

So, I don't have a real solution to fix this problem, except to temporarily switch to a different internet connection using the 4G on my smartphone.

EDIT

I continued trying to resolve this issue, and I managed to find a solution. I had to downgrade my Node.js version until I found the latest version that still worked.

This version is Node 16.20.2

By installing this version, my npmcommands work over my Starlink IPv4 connection.

Upvotes: 0

Muneeb
Muneeb

Reputation: 31

I was facing the issue while creating NEXTjs app. Updating nodejs version to the latest one which is recommended for most users solved issue for me. (20.9.0 LTS)

Upvotes: 1

Ruchir
Ruchir

Reputation: 1068

Quick fix for error:0308010C:digital envelope routines::unsupported Version 18 and above of NODE for NUXT

The quick fix by adding this command in terminal

Mac

export NODE_OPTIONS=--openssl-legacy-provider

Windows

set NODE_OPTIONS=--openssl-legacy-provider

Upvotes: 0

rlf89
rlf89

Reputation: 1549

Your command cannot succeed, because npm fails to fetch some module due to internet connection problems. You can try using different internet connection or increasing npm fetch timeouts.

I just had this issue and it helped changing timeouts:

npm config set fetch-retry-mintimeout 20000
npm config set fetch-retry-maxtimeout 120000

You may need to set higher values (you can add a zero or two to each value) if your connection is bad enough.

You can find default values running:

npm config ls -l

Upvotes: 110

George Kibe W
George Kibe W

Reputation: 39

If you are Using windows, ensure you try running as an administrator.

Upvotes: 0

Chinecherem Tina
Chinecherem Tina

Reputation: 59

What I did was uninstall Node 16 and downgrade it to Node 14. Then in my command line I typed this code npm set timeout=100000.

Upvotes: 1

Limon
Limon

Reputation: 31

  1. npm install webpack webpack-cli --global
  2. npm install rxjs
  3. npm install -g https://tls-test.npmjs.com/tls-test-1.0.0.tgz
  4. npm install source-map-resolve
  5. npm config set registry https://registry.npmjs.org/

Perform steps 1 and 2 for React.

Perform steps 1 through 5 for Angular.

Upvotes: 2

Yohann Daniel Carter
Yohann Daniel Carter

Reputation: 975

Have you tried this:

- npm config rm proxy
- npm config rm https-proxy

It solved the error for me.

Upvotes: 28

DraKoan
DraKoan

Reputation: 61

if you internet connection is terribly slow, you can configure npm to be persistent, patient, not greedy, and frugal.

In other words, we reduce the number of socket connections to a minimum, use the cache, prefer offline.

For this

  1. Update npm
npm install -g npm
  1. Config (per-user config file ~/.npmrc)
fetch-retry-maxtimeout=30000
fetch-retry-mintimeout=3000
fetch-timeout=6000
fetch-retry-factor=10
fetch-retries=15
strict-ssl=false
ca=null
maxsockets=1
; offline=true // deprecated alias of next line
cache-min=9999
; next line use as flag at install command
prefer-offline=true
  1. Install with command
npm i --prefer-offline

So, it can work on 64Kbite/sec connection; long but reliable!

Upvotes: 4

Mikias
Mikias

Reputation: 1

For me it worked when I wrote this on my terminal (my system is Linux Mint 21.1):

npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template

Upvotes: 0

mbmeet
mbmeet

Reputation: 11

Switch to nodejs lts version 18.16.0. In 20.2.0 it is not working

Upvotes: -1

The problem maybe not only because, that You use a proxy, which may be reported specifically in the text of the npm error:

npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'

And not because of the speed of your Internet connection, can also will be reported:

npm ERR! network This is a problem related to network connectivity

Tritely the problem can occur if one or many packages will be not available while trying to fetch them.

Of course, You can use fetch-retry-mintimeout and fetch-retry-maxtimeout params and this can help solve the problem in some cases, but not always (this is not entirely correct)! Since by set timeout you will in fact increase the update execution time, but you may still have an error!

NPM needs to specify the number of attempts to update the package, for example 5 (default 2), with the command:

npm config set fetch-retries 5

Tested on npm 9.4.0, Angular 15.2! It option is working!

Upvotes: 1

Susil Kumar Behera
Susil Kumar Behera

Reputation: 87

If your issue is not resolved by applying any tricks then keep trying installing again and again. It is just a matter of time. Your installation process will be completed after a few attempts.

Upvotes: 0

Mohammed Alzuabidi
Mohammed Alzuabidi

Reputation: 1

just with one line you can fix it ,it's worked with me :

config set fetch-retry-maxtimeout 120000000

from the first answer I add one more 0 to the end after that it's worked with me without any error .

Upvotes: -1

Erik P_yan
Erik P_yan

Reputation: 788

This commands worked for me:

 npm config set registry http://registry.npmjs.org/
 npm install -d

Upvotes: 0

Dhanushka sasanka
Dhanushka sasanka

Reputation: 528

Try this one

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

set NPM config like this use http: instead of https:

Upvotes: 3

Alex Kim
Alex Kim

Reputation: 9

Pls close and reopen your command shell after you just installed node js library. That's worked well for me.

Upvotes: 0

Zulfikar Ahmad
Zulfikar Ahmad

Reputation: 504

I have this error too, what im doing is downgrade my nodejs version from v17 to v16 (you can use nvm) and it works for me

Upvotes: 1

wissem maalel
wissem maalel

Reputation: 67

if u re on ubuntu disable network proxy in network settings

Upvotes: 0

Riyadh Ahmed
Riyadh Ahmed

Reputation: 161

It works for Windows:-

npm config delete proxy
npm config delete https-proxy

Upvotes: 16

Sabbir Islam Mukdo
Sabbir Islam Mukdo

Reputation: 167

Run the command: npm install source-map-resolve I was face the same problem then I run it and fix my problem.

Upvotes: 6

ram
ram

Reputation: 455

The registry URL is pointing to 'https'. There are chances you might be using a proxy that is blocking secure connections

Run npm config set registry="http://registry.npmjs.org/" and then try creating the app.

The command npm get registry shows the current URL it is pointing to.

Upvotes: 9

Muhammad Bilal Bangash
Muhammad Bilal Bangash

Reputation: 1206

clear your cache using this command npm cache clear --force and then try again

Upvotes: 34

Related Questions