当前位置: 首页 > 知识库问答 >
问题:

在angular 2中创建构建时出现JavaScript堆内存不足错误

周宏伯
2023-03-14

我想在angular 2中创建build,我写了 命令,并得到以下错误。

  180823 ms: Mark-sweep 1338.1 (1437.6) -> 1338.1 (1437.6) MB, 1325.4 / 0.0 ms [allocation failure] [GC in old space requested].
  182147 ms: Mark-sweep 1338.1 (1437.6) -> 1338.1 (1437.6) MB, 1323.7 / 0.0 ms [allocation failure] [GC in old space requested].
  183495 ms: Mark-sweep 1338.1 (1437.6) -> 1344.6 (1418.6) MB, 1347.4 / 0.0 ms [last resort gc].
  184844 ms: Mark-sweep 1344.6 (1418.6) -> 1351.3 (1418.6) MB, 1348.6 / 0.0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x5ec47cfb51 <JS Object>
    1: token(aka token) [0x5ec4704381 <undefined>:1724] [pc=0x3e2345467b26] (this=0x5ec4704381 <undefined>,type=0x5ec4704fb1 <String[4]: name>,value=0x3363e2ffb931 <String[62]: __WEBPACK_IMPORTED_MODULE_35__angular_material_button_button__>,is_comment=0x5ec4704381 <undefined>)
    2: arguments adaptor frame: 2->3
    3: read_word(aka read_word) [0x5ec4704381 <undefined>:~1957] [pc=0x3e23435a05fb]...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [@angular/cli]
 2: 0x1096a4c [@angular/cli]
 3: v8::Utils::ReportApiFailure(char const*, char const*) [@angular/cli]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [@angular/cli]
 5: v8::internal::Factory::NewTransitionArray(int) [@angular/cli]
 6: v8::internal::TransitionArray::Insert(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Map>, v8::internal::SimpleTransitionFlag) [@angular/cli]
 7: v8::internal::Map::ShareDescriptor(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal::Descriptor*) [@angular/cli]
 8: v8::internal::Map::CopyAddDescriptor(v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [@angular/cli]
 9: v8::internal::Map::CopyWithField(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::Representation, v8::internal::TransitionFlag) [@angular/cli]
10: v8::internal::Map::TransitionToDataProperty(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::StoreFromKeyed) [@angular/cli]
11: v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::StoreFromKeyed) [@angular/cli]
12: v8::internal::StoreIC::LookupForWrite(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [@angular/cli]
13: v8::internal::StoreIC::UpdateCaches(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [@angular/cli]
14: v8::internal::StoreIC::Store(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [@angular/cli]
15: v8::internal::Runtime_StoreIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [@angular/cli]
16: 0x3e2341a092a7
Aborted (core dumped)

我还在我项目中尝试了以下命令:

node --max-old-space-size=8192 node_modules/@angular/compiler-cli/src/main.js -p tsconfig-aot.json

并得到以下错误:

错误:eNoent:没有这样的文件或目录,lstat'tsconfig-aot.json'的错误(本机)位于object.main(/root/desktop/rc1-dev/client/node_modules/@angular/tsc-wrapped/src/main.js:20:16)的main(/root/desktop/rc1-dev/client/node_modules/@angular/compiler-cli/src/main.js:14:16)的object.fs.lstatsync(fs.js:982:18)处。(/root/desktop/rc1-dev/client/node_modules/@angular/compiler-cli/src/main.js:30:5)at module._compile(module.js:570:32)at object.module._extensions..js(module.js:579:10)at module.load(module.js:487:32)at module.load(module.js:446:12)at function.module._load(module.js:438:3)编译失败

共有3个答案

秦俊发
2023-03-14

使用 (非常肯定--aot和--no-sourceMap现在是默认的)构建产品。

Gzipping已从CLI本身中删除。您的Web服务器可以为您处理gzipping,或者您可以管道上一个gulp任务或类似的压缩您的dist文件夹后构建。

src https://github.com/angular/angular-cli/issues/5482

郁明诚
2023-03-14

不要在生产中使用angular-cli托管应用程序

angular-cli开发人员不推荐它,正如您在这里看到的那样!

对于开发构建,您将只需要1 GB的内存,但是生产构建是非常资源密集型的,它可能需要超过2GB的RAM。

对于生产,您应该在具有2GB以上ram的PC中构建应用程序,并将/dist文件夹传输到生产服务器。

null

null

狄灵均
2023-03-14

尝试通过以下脚本在json包中运行构建脚本:

"scripts": {
   "build-prod": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --prod --aot --no-sourcemap"
}

然后运行“npm run build-prod”。

 类似资料:
  • 尝试使用https://github.com/endel/regene-memory-limit增加大小限制,但仍然无法构建。我需要更改node_modules中的任何地方吗? 10%构建模块6/8模块2活动...\bootstrap\dist\css\bootstrap 90%块资产处理<---最后几个GCs---> 174152 ms:标记-扫描1266.2(1435.6)->1265.2(1

  • 我有一个Vue应用程序。当为该应用程序运行时,它失败了,错误为“致命错误:CALL_AND_RETRY_LAST Allocation failed-JavaScript heap out of memory” 不显示任何错误 我已经尝试使用--max_old_space_size,但它不起作用。

  • 我在运行应用程序时遇到gradle生成错误。我使用的是8GB内存的windows 10,Android studio 4.0.1版 内存不足:Java堆空间。请在项目的Gradle中为Gradle分配更多内存。属性文件。例如,下面的一行,在渐变中。属性文件,将最大Java堆大小设置为1024 MB:org。格雷德尔。jvmargs=-Xmx1024m 即使遵循相同的步骤,我也无法运行该应用程序。有

  • 安全上下文:000001af8a2cfb61 2:/*匿名*/[C:\project_folder\node_modules\source-map\lib\source-node.js:100][pc=0000016e99866533](this=00000346870554e1,mapping=000003c18fdc93c9)3:参数适配器框架:3->1 4:InnerArrayForEach

  • 问题内容: 运行时出现以下错误: 严重错误:CALL_AND_RETRY_LAST分配失败-JavaScript堆内存不足 有没有办法全局增加node.js内存限制? 问题答案: 您可以使用以下命令启动NPM: 如所描述的在这里,默认为4000(4GB)。