当 NativeScript 应用程序与 Webpack 捆绑时,会出现 Javascript 堆错误。
fatal error :接近堆限制的标记压缩无效分配失败 - JavaScript 堆内存不足
这是我使用运行时遇到的错误
tns run android --bundle --env.aot --env.uglify
nativescript version 5.2.2
@angular/core: "~7.2.0
nativescript-dev-webpack": "^0.20.3
@angular/compiler-cli": "~7.2.0
详细日志
<--- 最后几次 GC --->
[31199:0x24e6180] 38234 ms: Mark-sweep 1367.2 (1453.5) -> 1363.6 (1458.5) MB, 912.0 / 0.0 ms (average mu = 0.116, current mu = 0.044) allocation failure scavenge might not succeed [31199:0x24e6180]
39132 ms: Mark-sweep 1372.4 (1458.5) -> 1368.5 (1458.5) MB, 844.5 / 0.0 ms (average mu = 0.087, current mu = 0.060) allocation failure GC in old space requested
<--- JS 堆栈跟踪 --->
==== JS 堆栈跟踪 ========================================== =
0: ExitFrame [pc: 0x2d645c5dbe1d]
Security context: 0x10886211e6e1 <JSObject>
1: bindWorker(aka bindWorker) [0x39b993a31201]
[/home/user/jishnu/projects/oes-dt-
mobile/node_modules/typescript/lib/typescript.js:~28311] [pc=0x2d645d75c74d]
(this=0x005cd5b026f1 <undefined>,node=0x06f6ec3100a1 <NodeObject map =
0xe7113ce3aa1>)
2: bind(aka bind) [0x39b993a31101] [/home/user/jishnu/projects/oes-dt-
mobile/node_modules/typescript/lib/ty...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x8daaa0 node::Abort() [node]
2: 0x8daaec [node]
3: 0xad73ce v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
4: 0xad7604 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
5: 0xec4c32 [node]
6: 0xec4d38 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [node]
7: 0xed0e12 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
8: 0xed1744 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
9: 0xed43b1 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [node]
10: 0xe9c695 [node]
11: 0xea1354 v8::internal::Factory::NewByteArray(int, v8::internal::PretenureFlag) [node]
12: 0xe2a88a v8::internal::TranslationBuffer::CreateByteArray(v8::internal::Factory*) [node]
13: 0xc41edf v8::internal::compiler::CodeGenerator::GenerateDeoptimizationData() [node]
14: 0xc42672 v8::internal::compiler::CodeGenerator::FinalizeCode() [node]
15: 0xd5167b v8::internal::compiler::PipelineImpl::FinalizeCode() [node]
16: 0xd51a8d v8::internal::compiler::PipelineCompilationJob::FinalizeJobImpl(v8::internal::Isolate*) [node]
17: 0xc1562d v8::internal::Compiler::FinalizeCompilationJob(v8::internal::OptimizedCompilationJob*, v8::internal::Isolate*) [node]
18: 0xc0bbbb v8::internal::OptimizingCompileDispatcher::InstallOptimizedFunctions() [node]
19: 0xe720bb v8::internal::StackGuard::HandleInterrupts() [node]
20: 0x113ced5 v8::internal::Runtime_StackGuard(int, v8::internal::Object**, v8::internal::Isolate*) [node]
21: 0x2d645c5dbe1d
没有 --bundle 的命令 tns run
不存在错误。添加一些工作人员以进行某些应用程序优化后出现错误。已关注 NativeScript Worker Loader and NativeScriptWorkerPlugin用于通过 webpack 捆绑添加工作人员。
最佳答案
在终端窗口中运行此命令:
导出 NODE_OPTIONS=--max-old-space-size=4096
然后运行tns run ...
命令,它应该可以解决问题。
如果将 export ...
添加到 ~/.bashrc (或类似文件),则无需在每次启动新终端时手动运行它。
关于webpack - NativeScript 应用程序与 Webpack 捆绑时出现 Javascript 堆错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55356969/