OOM solution caused by npm install

Problem record

When I configured the npm development environment on Huawei Cloud Server, the SSH remote connection kept dropping. I had no choice but to file a work order and was told that the OOM problem was caused by NPM install. I'm speechless, I still have this problem after breaking NPM!
Insert image description here

Solution

Create a file named:.npmrc under the project path
Write inside the file:

NODE_OPTIONS=--max-old-space-size=4096

4096The unit of isM. If it is not enough, please automatically increase it. There is something special about this number, it is best to be a multiple of 1024.
Then you can use the command: npm config ls to check whether the configuration takes effect

base) ➜  gatsby-cds-blog git:(master)npm config ls
; "user" config from /Users/chendongsheng/.npmrc

chromedriver-cdnurl = "https://npm.taobao.org/mirrors/chromedriver" 
couchbase-binary-host-mirror = "https://npm.taobao.org/mirrors/couchbase/v{version}" 
debug-binary-host-mirror = "https://npm.taobao.org/mirrors/node-inspector" 
disturl = "https://npm.taobao.org/dist" 
electron-mirror = "https://npm.taobao.org/mirrors/electron/" 
flow-bin-binary-host-mirror = "https://npm.taobao.org/mirrors/flow/v" 
fse-binary-host-mirror = "https://npm.taobao.org/mirrors/fsevents" 
fuse-bindings-binary-host-mirror = "https://npm.taobao.org/mirrors/fuse-bindings/v{version}" 
git4win-mirror = "https://npm.taobao.org/mirrors/git-for-windows" 
gl-binary-host-mirror = "https://npm.taobao.org/mirrors/gl/v{version}" 
grpc-node-binary-host-mirror = "https://npm.taobao.org/mirrors" 
hackrf-binary-host-mirror = "https://npm.taobao.org/mirrors/hackrf/v{version}" 
home = "https://npm.taobao.org" 
leveldown-binary-host-mirror = "https://npm.taobao.org/mirrors/leveldown/v{version}" 
leveldown-hyper-binary-host-mirror = "https://npm.taobao.org/mirrors/leveldown-hyper/v{version}" 
mknod-binary-host-mirror = "https://npm.taobao.org/mirrors/mknod/v{version}" 
node-sqlite3-binary-host-mirror = "https://npm.taobao.org/mirrors" 
node-tk5-binary-host-mirror = "https://npm.taobao.org/mirrors/node-tk5/v{version}" 
nodegit-binary-host-mirror = "https://npm.taobao.org/mirrors/nodegit/v{version}/" 
operadriver-cdnurl = "https://npm.taobao.org/mirrors/operadriver" 
phantomjs-cdnurl = "https://npm.taobao.org/mirrors/phantomjs" 
profiler-binary-host-mirror = "https://npm.taobao.org/mirrors/node-inspector/" 
proxy = "http://127.0.0.1:7890" 
puppeteer-download-host = "https://npm.taobao.org/mirrors" 
python-mirror = "https://npm.taobao.org/mirrors/python" 
rabin-binary-host-mirror = "https://npm.taobao.org/mirrors/rabin/v{version}" 
registry = "https://registry.npmmirror.com/" 
sass-binary-site = "https://npm.taobao.org/mirrors/node-sass" 
sodium-prebuilt-binary-host-mirror = "https://npm.taobao.org/mirrors/sodium-prebuilt/v{version}" 
sqlite3-binary-site = "https://npm.taobao.org/mirrors/sqlite3" 
utf-8-validate-binary-host-mirror = "https://npm.taobao.org/mirrors/utf-8-validate/v{version}" 
utp-native-binary-host-mirror = "https://npm.taobao.org/mirrors/utp-native/v{version}" 
zmq-prebuilt-binary-host-mirror = "https://npm.taobao.org/mirrors/zmq-prebuilt/v{version}" 

; "project" config from /Users/chendongsheng/github/react_learner/gatsby-cds-blog/.npmrc

NODE_OPTIONS = "--max-old-space-size=4096" 

; node bin location = /usr/local/bin/node
; node version = v20.9.0
; npm local prefix = /Users/chendongsheng/github/react_learner/gatsby-cds-blog
; npm version = 10.1.0
; cwd = /Users/chendongsheng/github/react_learner/gatsby-cds-blog
; HOME = /Users/chendongsheng
; Run `npm config ls -l` to show all defaults.

Continue the installation. If the problem still exists, please continue to increase the value until the problem is solved.
But if your memory is only 2G, but it is not enough, you need to increase the swap space at this time and use the hard disk space as ram.
This can also solve the problem: please refer to: Tutorial on setting up swap space

Linux restart troubleshooting method

How to troubleshoot the reason why Linux automatically restarts

Automatic restart of Linux servers is a common failure phenomenon and may be caused by many reasons. When troubleshooting this issue, you can follow these steps:

  1. View restart time

First, you can check the restart time through the last or uptime command. For example:

[root@localhost ~]# last
reboot    Wed 2023-11-15 12:00:00 CST

This means the system restarted at 2023-11-15 12:00:00 CST.

  1. View system log

The system log usually records the reason for the restart. You can use the grep command to find keywords such as panic, error, exception, and shutdown. For example:

[root@localhost ~]# cat /var/log/messages | grep -E -i "panic|error|exception|shutdown"

This will display lines in the system log containing the above keywords.

  1. Check scheduled tasks

Scheduled tasks may cause the system to automatically restart. You can use the crontab -l command to view the scheduled task list.

  1. Check for hardware failure

Hardware failure may also cause the system to automatically restart. You can check whether there are any abnormalities in hardware such as CPU, memory, disk, and power supply.

If the cause of the reboot cannot be determined through the above steps, you can use the kdump and crash tools to generate a kernel crash dump file. You can then use analysis tools to view the dump file to obtain more information.

  • Common reasons why Linux automatically restarts
    The following are some common reasons why Linux automatically restarts:

  • Software errors: For example, a program has a bug that causes the system to crash.

  • Hardware failure: For example, memory corruption or power failure.

  • Configuration errors: For example, there are errors in the system configuration files.

  • Malware: For example, a virus or Trojan that causes the system to automatically reboot.


  • Reference for this article

Someone mentioned it on GitHubgithub-npm-ISSUE
statck overflow also has related records: npm install stackoverflow

おすすめ

転載: blog.csdn.net/sexyluna/article/details/134375814