others-how to solve read ECONNRESET error when trying to install nodejs module using npx?

1. Purpose

In this post, I will demonstrate how to solve read ECONNRESET error when trying to install nodejs module using npx. Such as following error:

➜  react_native_macos_app1 npx react-native-macos-init
Need to install the following packages:
  react-native-macos-init
Ok to proceed? (y) y
npm ERR! code ECONNRESET
npm ERR! syscall read
npm ERR! errno ECONNRESET
npm ERR! network Invalid response body while trying to fetch https://registry.npmjs.org/extract-github: read ECONNRESET
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
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'

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/bswen/.npm/_logs/2022-06-06T08_56_00_375Z-debug.log
➜  react_native_macos_app1



2. Solution

1) What is ECONNRESET error?

“ECONNRESET” means the other side of the TCP conversation abruptly closed its end of the connection. This is most probably due to one or more application protocol errors. You could look at the API server logs to see if it complains about something.

What could also be the case: at random times, the other side is overloaded and simply kills the connection as a result. If that’s the case, depends on what you’re connecting to exactly…

But one thing’s for sure: you indeed have a read error on your TCP connection which causes the exception. You can see that by looking at the error code you posted in your edit, which confirms it.

2) How to debug the ECONNRESET error?

You can turn on the --abort-on-uncaught-exception switch as follows:

--abort-on-uncaught-exception#
Added in: v0.10.8
Aborting instead of exiting causes a core file to be generated for post-mortem analysis using a debugger (such as lldb, gdb, and mdb).

If this flag is passed, the behavior can still be set to not abort through process.setUncaughtExceptionCaptureCallback() (and through usage of the node:domain module that uses it).
./node --report-uncaught-exception xxx.js


Then you will get the dump file :

Uncaught Error

FROM
lala ([eval]:1:19)
[eval]:1:39
Script.runInThisContext (vm.js:123:20)
Object.runInThisContext (vm.js:313:38)
Object.<anonymous> ([eval]-wrapper:9:26)
Module._compile (internal/modules/cjs/loader.js:779:30)
evalScript (internal/process/execution.js:80:25)
internal/main/eval_string.js:23:3

$ ls
core

3) Solution that works for me

Just restart iterm.



3. Summary

In this post, I demonstrated how to debug and solve the ECONNRESET error when using node.js. That’s it, thanks for your reading.

-->