Firestore addDoc 使 npm 崩溃

Firestore addDoc crashes npm

我正在像这样导入 firestore

import { getFirestore, addDoc } from "firebase/firestore";

但我认为它正在从 运行 我的 React 应用程序中破坏 npm 因为它在尝试编译时挂起然后说

<--- Last few GCs --->

[35196:0x7fb905900000]    69759 ms: Scavenge (reduce) 4063.1 (4140.1) -> 4063.0 (4141.1) MB, 6.0 / 0.0 ms  (average mu = 0.181, current mu = 0.132) allocation failure 
[35196:0x7fb905900000]    74736 ms: Mark-sweep (reduce) 4063.5 (4141.1) -> 4063.1 (4141.1) MB, 4957.0 / 0.1 ms  (+ 44.8 ms in 11 steps since start of marking, biggest step 6.0 ms, walltime since start of marking 5015 ms) (average mu = 0.186, current mu = 

<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x1053472b5 node::Abort() [/usr/local/bin/node]
 2: 0x105347438 node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0x1054bebb7 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 4: 0x1054beb53 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 5: 0x10565d1d5 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
 6: 0x1056611fb v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/usr/local/bin/node]
 7: 0x10565dadc v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
 8: 0x10565af8a v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
 9: 0x1056682e0 v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x105668361 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
11: 0x1056352b7 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/usr/local/bin/node]
12: 0x1059e129e v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
13: 0x105d83299 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]

注意:当我删除 addDoc 但在 import 语句中保留 getFirebase 时,不会发生这种情况,如下所示: import { getFirestore } from "firebase/firestore";

如果你看到上面的错误:"Allocation failed - JavaScript heap out of memory",说明你的NodeJS application has ran out of memory,已经消耗了比分配的内存更多的内存,最终导致它自杀。

要解决这个问题你需要增加内存限制使用命令-- max-old-space-size。它可以避免内存限制问题。您也可以尝试先更新 nodejs 的版本,然后再 运行 以下命令:

export NODE_OPTIONS=--max_old_space_size=<size>

Just a note, on a machine with 2 GB of memory, consider setting this to 1536 (1.5 GB) to leave some memory for other uses and avoid memory swapping.

我通过删除我的节点模块文件夹然后 运行 npm i

解决了这个问题