2017-09-01 13 views
1

我同時使用npm start我的角度網頁出現以下錯誤。的Javascript堆出來的內存

C:\TPO\Client\Angular>ng serve 
Your global Angular CLI version (1.3.2) is greater than your local 
version (1.0.4). The local Angular CLI version is used. 

To disable this warning use "ng set --global warnings.versionMismatch=false". 
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200 ** 
10% building modules 4/4 modules 0 active 
<--- Last few GCs ---> 

    118169 ms: Mark-sweep 1348.4 (1404.3) -> 1348.1 (1404.3) MB, 1338.9/0.0 ms [allocation failure] [GC in old space requested]. 
    119374 ms: Mark-sweep 1348.1 (1404.3) -> 1348.1 (1404.3) MB, 1204.7/0.0 ms [allocation failure] [GC in old space requested]. 
    121097 ms: Mark-sweep 1348.1 (1404.3) -> 1362.7 (1403.3) MB, 1723.2/0.0 ms [last resort gc]. 
    122416 ms: Mark-sweep 1362.7 (1403.3) -> 1377.4 (1403.3) MB, 1317.9/0.0 ms [last resort gc]. 


<--- JS stacktrace ---> 

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

Security context: 0000034B7C13FA99 <JS Object> 
    1: set [native collection.js:~252] [pc=00000174AF1BC2E1] (this=000003AD36FBC469 <a Map with map 0000002CF18113B1>,r=000002D7A3418CD9 <String[12]: 32741,580445>,z=1) 
    2: /* anonymous */ [C:\TPO\Client\Angular\node_modules\typescript\lib\typescript.js:~2177] [pc=00000174ADC9EBD0] (this=000001D0EA536CE1 <JS Global Object>,value=1,key=000002D7A3418CD9 <String[12]: 32741,580445>) 
    3: arg... 

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 
+0

你看看https://stackoverflow.com/questions/45322901/javascript-heap-out-of-memory-in-angular-2?也許這可以幫助你 –

+0

我愛你。有效。我浪費了整整一天的時間。 –

回答

3

除非有什麼不對您的應用程序,以擺脫這個問題(如this answer建議)的最簡單的方法是增加node.js的

在Windows上可以做到這一點堆大小導航到

C:\Users\your_user_name\%AppData%\Roaming\npm 

,然後編輯ng.cmd在那裏:

@IF EXIST "%~dp0\node.exe" (
    "%~dp0\node.exe" --max_old_space_size=4096 "%~dp0\node_modules\@angular\cli\bin\ng" %* 
) ELSE (
    @SETLOCAL 
    @SET PATHEXT=%PATHEXT:;.JS;=;% 
    node --max_old_space_size=4096 "%~dp0\node_modules\@angular\cli\bin\ng" %* 
) 

--max_old_space_size=4096將節點的V8引擎的堆大小設置爲以MB爲單位的相應值(在我們的情況下,這是4096,但可能您可能會根據工作站的功能對其進行微調)而不是默認值1400 MB

+0

非常感謝解決方案。這是工作。 –