在构建 ios react-native 应用程序时,我在 Visual Studio 应用程序中心 (CI) 中遇到了这个问题。我已经解决了 github 中的问题和其他有关此问题的 stackoverflow 问题。他们都建议像这样更改节点内存。--expose-gc --max_old_space_size=32000
.但我不知道如何在 CI 中改变它。
我尝试了一种方法,我在下面的捆绑命令中找到了node_modules/react-native/scripts/react-native-xcode.sh
$NODE_BINARY $CLI_PATH bundle \
--entry-file "$ENTRY_FILE" \
--platform ios \
--dev $DEV \
--reset-cache \
--bundle-output "$BUNDLE_FILE" \
--assets-dest "$DEST"
所以在appcenter-pre-build.sh
我写的代码将添加--expose-gc --max_old_space_size=32000
到上面的命令中,如下所示
$NODE_BINARY --expose-gc --max_old_space_size=32000 $CLI_PATH bundle \
--entry-file "$ENTRY_FILE" \
--platform ios \
--dev $DEV \
--reset-cache \
--bundle-output "$BUNDLE_FILE" \
--assets-dest "$DEST"
并尝试了,即使我遇到了同样的错误。
transform[stdout]: <--- JS stacktrace --->
transform[stdout]:
transform[stdout]: ==== JS stack trace =========================================
transform[stdout]:
transform[stdout]: Security context: 0x194baa3cf781 <JS Object>
transform[stdout]: 1: popContext [/Users/vsts/agent/2.127.0/work/1/s/node_modules/babel-traverse/lib/path/context.js:~222] [pc=0xb87791150c3] (this=0x399c406adfc9 <a NodePath with map 0x1b8e272b61a1>)
transform[stdout]: 2: visitQueue [/Users/vsts/agent/2.127.0/work/1/s/node_modules/babel-traverse/lib/context.js:~114] [pc=0xb8778a8efd2] (this=0xa337d831709 <a TraversalContext with map 0x1b8e272b5d81>,queue=0xa337d831751 <JS ...
transform[stdout]:
transform[stderr]: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
transform[stderr]: 1: node::Abort() [/usr/local/Cellar/node@6/6.12.3/bin/node]
transform[stderr]: 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/Cellar/node@6/6.12.3/bin/node]
transform[stderr]: 3: v8::Utils::ReportApiFailure(char const*, char const*) [/usr/local/Cellar/node@6/6.12.3/bin/node]
transform[stderr]: 4: v8::Utils::ApiCheck(bool, char const*, char const*) [/usr/local/Cellar/node@6/6.12.3/bin/node]
transform[stderr]: 5: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/Cellar/node@6/6.12.3/bin/node]
transform[stderr]: 6: v8::internal::Factory::NewRawOneByteString(int, v8::internal::PretenureFlag) [/usr/local/Cellar/node@6/6.12.3/bin/node]
transform[stderr]: 7: v8::internal::Factory::NewStringFromOneByte(v8::internal::Vector<unsigned char const>, v8::internal::PretenureFlag) [/usr/local/Cellar/node@6/6.12.3/bin/node]
transform[stderr]: 8: v8::internal::Factory::NumberToString(v8::internal::Handle<v8::internal::Object>, bool) [/usr/local/Cellar/node@6/6.12.3/bin/node]
transform[stderr]: 9: v8::internal::Object::ToString(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>) [/usr/local/Cellar/node@6/6.12.3/bin/node]
transform[stderr]: 10: v8::internal::Object::ConvertToName(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>) [/usr/local/Cellar/node@6/6.12.3/bin/node]
transform[stderr]: 11: v8::internal::LookupIterator::PropertyOrElement(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, bool*, v8::internal::LookupIterator::Configuration) [/usr/local/Cellar/node@6/6.12.3/bin/node]
transform[stderr]: 12: v8::internal::Runtime::GetObjectProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [/usr/local/Cellar/node@6/6.12.3/bin/node]
transform[stderr]: 13: v8::internal::Runtime_KeyedGetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/Cellar/node@6/6.12.3/bin/node]
transform[stderr]: 14: 0xb87779092a7
transform[stdout]:
transform[stdout]: <--- Last few GCs --->