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

24

66

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.
Aphorize answered 23/5, 2021 at 8:12 Comment(1)
timeout issues may occur due to connectivity issue. Make sure you've an active internet connection with a decent speedLinkwork
F
108

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
Fuliginous answered 2/2, 2022 at 15:45 Comment(1)
npm config ls -l | grep timeout on linux to go straight to the meaningful config tagsLattimore
M
33

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

Moreno answered 23/5, 2021 at 8:18 Comment(2)
can you explain how can this resolve a Socket timeout issue ?Yellowlegs
@Yellowlegs - In some cases the Socket Timeout comes with a nearby "Invalid Response Body" error. I'm not sure why this error occurs... maybe checksum validation fails... just a guess. Clearing the cache seems to solve this subset of errors. SEE: #64308804Deppy
M
28

Have you tried this:

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

It solved the error for me.

Mavilia answered 16/2, 2022 at 9:39 Comment(1)
I got a different error (peer dependency issue, not related to this command) after I used this which is good but confused because i do not recall setting any proxy or https proxy.Hessenassau
I
16

It works for Windows:-

npm config delete proxy
npm config delete https-proxy
Inflated answered 16/2, 2022 at 13:58 Comment(1)
also I had private dns (dns.adguard.com) on. turning it off helpedSlippy
G
9

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.

Gunstock answered 23/5, 2021 at 8:30 Comment(0)
C
6

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

Climactic answered 18/1, 2022 at 11:12 Comment(2)
While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.Sepaloid
That package is deprecated (source).Ungainly
O
3

Try this one

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

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

Open answered 13/9, 2022 at 6:56 Comment(0)
P
3

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!

Pierides answered 19/8, 2023 at 12:26 Comment(0)
P
2
  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.

Parada answered 27/7, 2022 at 7:14 Comment(0)
D
1

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.

Danilodanio answered 21/12, 2021 at 13:34 Comment(2)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewInactivate
What makes you think the version change was what did it? Did you test each one separately? This does not seem particularly useful for others to reproduce.Colp
L
1

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

Lithia answered 1/4, 2022 at 12:30 Comment(0)
N
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!

Neufer answered 16/3, 2023 at 16:5 Comment(0)
H
0

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

Heterogenetic answered 22/3, 2022 at 7:29 Comment(0)
S
0

if u re on ubuntu disable network proxy in network settings

Seumas answered 30/3, 2022 at 9:3 Comment(0)
C
0

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

Coleville answered 14/4, 2022 at 12:13 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Applejack
E
0

This commands worked for me:

 npm config set registry http://registry.npmjs.org/
 npm install -d
Elseelset answered 6/12, 2022 at 8:46 Comment(0)
V
0

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
Volumed answered 29/12, 2022 at 13:20 Comment(0)
W
0

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.

Wisniewski answered 8/2, 2023 at 11:31 Comment(0)
P
0

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
Passageway answered 9/7, 2023 at 10:56 Comment(0)
G
0

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)

Granduncle answered 25/10, 2023 at 18:4 Comment(1)
Welcome to Stack Overflow! Thank you for your answer. Please provide more details about your solution. Code snippets, high quality descriptions, or any relevant information would be great. Clear and concise answers are more helpful and easier to understand for everyone. Edit your answer with specifics to raise the quality of your answer. For more information: How To: Write good answers. Happy coding!Elishaelision
O
0
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.

Oreste answered 29/11, 2023 at 12:41 Comment(1)
Today I Installed node 21.x and the problem seems to be solved in this version.Oreste
T
0

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.

Thrave answered 1/6 at 8:58 Comment(0)
C
-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 .

Chadwickchae answered 22/1, 2023 at 1:19 Comment(1)
This repeats the solution from the top answer: #67658099 as you mention, and there were already comments under it suggesting potentially longer timeout values. Please reserve posting answers for when you have a novel solution to a question. You can post comments where needed under others' answers once you reach 50 reputation.Colp
J
-1

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

Jointless answered 23/5, 2023 at 4:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.