在我的 CRA 项目中,每次运行它时,我都会在控制台中遇到此错误。我认为这是由于打字稿服务器造成的。有办法解决吗
99% done plugins webpack-hot-middlewarewebpack built preview 7c330f0bfd3e44c3a97b in 6446ms
Issues checking in progress...
<--- Last few GCs --->
[15997:0x7fccd3700000] 618460 ms: Mark-sweep (reduce) 2043.8 (2082.1) -> 2042.4 (2082.1) MB, 3304.1 / 0.0 ms (average mu = 0.202, current mu = 0.179) allocation failure scavenge might not succeed
[15997:0x7fccd3700000] 622127 ms: Mark-sweep (reduce) 2043.5 (2082.1) -> 2042.4 (2081.8) MB, 3661.0 / 0.0 ms (average mu = 0.106, current mu = 0.002) allocation failure scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x10e141815 node::Abort() (.cold.1) [/usr/local/bin/node]
2: 0x10ce40aa9 node::Abort() [/usr/local/bin/node]
3: 0x10ce40c1f node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
4: 0x10cfc1877 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
5: 0x10cfc1813 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
6: 0x10d162c65 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
7: 0x10d166cad v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/usr/local/bin/node]
8: 0x10d16358d v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
9: 0x10d160aad v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
10: 0x10d16dde0 v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
11: 0x10d16de61 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
12: 0x10d13afb7 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/usr/local/bin/node]
13: 0x10d4f089e v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
14: 0x10d89a2b9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
15: 0x10d82a983 Builtins_FastNewClosure [/usr/local/bin/node]
16: 0x119cedeb8
RpcIpcMessagePortClosedError: Process 15997 exited [SIGABRT].
Issues checking service aborted - probably out of memory. Check the `memoryLimit` option in the ForkTsCheckerWebpackPlugin configuration.
If increasing the memory doesn't solve the issue, it's most probably a bug in the TypeScript or EsLint.
RpcIpcMessagePortClosedError: Process 15997 exited [SIGABRT].
Issues checking service aborted - probably out of memory. Check the `memoryLimit` option in the ForkTsCheckerWebpackPlugin configuration.
If increasing the memory doesn't solve the issue, it's most probably a bug in the TypeScript or EsLint.
webpack building...
99%
这可能是由于内存泄漏造成的。只需增加分配给 Node.js 的内存就可以解决该错误。
在您的终端中输入:
export NODE_OPTIONS="--max-old-space-size=2048"
如果您使用的是 Windows 运行:
export NODE_OPTIONS="--max-old-space-size=2048"
注意:
size=2048
是您将分配给node.js的内存(MB),默认为512 MB
更新:如果您在使用 Jest 运行单元测试时遇到此问题,这可以解决它。
我今天遇到了同样的问题,这是我解决的方法:
jest.config.js
coverageProvider: 'v8'
"jest -w 1"
如果不起作用,请考虑将您的 node 版本升级到至少 16.10
它对我有用,在 Ubuntu 上,但该值必须是 5096(否则会失败)。
我不知道现在回答是否为时已晚,但问题是可用内存。如果尝试对应用程序进行 docker 化,请确保在 Docker 桌面中设置足够的内存分配。 前往:
Settings -> Resources -> Increase Swap and Memory limits
对我来说,4 GB 内存限制和 2GB 交换大小解决了这个问题。