关于ng build编译报错
1.错误信息
- 在执行ng build --aot --prod 时会报这个错误信息
91% additional asset processing
<--- Last few GCs --->680083 ms: Mark-sweep 1341.3 (1437.0) -> 1339.8 (1437.0) MB, 991.9 / 0.0 ms [allocation failure] [GC in old space requested].
681044 ms: Mark-sweep 1339.8 (1437.0) -> 1339.8 (1437.0) MB, 960.9 / 0.0 ms [allocation failure] [GC in old space requested].
682011 ms: Mark-sweep 1339.8 (1437.0) -> 1340.9 (1412.0) MB, 966.0 / 0.0 ms [last resort gc].
682986 ms: Mark-sweep 1340.9 (1412.0) -> 1342.1 (1412.0) MB, 974.9 / 0.0 ms [last resort gc].<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0000019861ECFB61 <JS Object>
1: /* anonymous */ [D:\MyProject\node_modules\webpack-sources\node_modules\source-map\lib\source-map-consumer.js:~142] [pc=000000411A16D6AE] (this=00000294368EDB49 <a BasicSourceMapConsumer with map 000003BC1D766499>,mapping=0000039E0356A939 <a Mapping with map 000003BC1D766C29>)
2: arguments adaptor frame: 3->1
3: map [native array.js:~994] [pc=000000411A15B70C] (thi...FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
2.解决方案
1.在项目 myProject\node_modules\.bin
文件夹下面找到ng.cmd
和 ngc.cmd
文件添加配置信息
--max_old_space_size=5048
然后配置成如下
(1)ng.cmd
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" --max_old_space_size=5048 "%~dp0\..\@angular\cli\bin\ng" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node --max_old_space_size=5048 "%~dp0\..\@angular\cli\bin\ng" %*
)
(2)ngc.cmd
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" --max_old_space_size=5048 "%~dp0\..\@angular\compiler-cli\src\main.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node --max_old_space_size=5048 "%~dp0\..\@angular\compiler-cli\src\main.js" %*
)
这样就解决上面编译报的错误信息了