node.js版本管理和内存溢出

版本管理

在 WSL 上,我用 n 管理 node 版本;在 Win 上,我用 nvm 管理 node。如果用 nvm 要重新给全局的 node_module 设置环境变量,因为 nvm 会把它删掉😵

sudo n latest 会很慢,下载到 40% 左右就会断掉,因为它不会走代理

sudo -E n latest 就很快,像喝水一样

目前我的 WSL 可以正常走 Win 的代理,git 一般没问题。不过配置的过程断断续续的,我没有记下来,可能只是在 %USERPROFILE%\.wslconfig 里加了 networkingMode=mirrored 和 autoProxy=true

build 内存溢出

build Open-WebUI 的时候,出现了如下报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
rendering chunks (179)...
<--- Last few GCs --->

[34877:0x76335a0] 48848 ms: Scavenge 2020.6 (2076.4) -> 2019.7 (2086.2) MB, 14.60 / 0.00 ms (average mu = 0.663, current mu = 0.876) allocation failure;
[34877:0x76335a0] 48892 ms: Scavenge 2027.0 (2086.6) -> 2024.4 (2087.2) MB, 15.86 / 0.00 ms (average mu = 0.663, current mu = 0.876) allocation failure;
[34877:0x76335a0] 48952 ms: Scavenge 2028.3 (2087.6) -> 2026.5 (2106.6) MB, 42.90 / 0.00 ms (average mu = 0.663, current mu = 0.876) allocation failure;


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

1: 0xcc08f6 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [node]
2: 0x1054130 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]
3: 0x1054417 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]
4: 0x1273655 [node]
5: 0x128a178 [node]
6: 0x126167e v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
7: 0x1262964 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
8: 0x1240625 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
9: 0x1670bec v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
10: 0x7f20326653f6
Aborted

这是 ChatGPT 的回答

试了前两种方法,似乎只有第一种 NODE_OPTIONS="--max-old-space-size=4096" npm run build 有用