Angular-cli 'JavaScript heap out of memory' on asset optimization

后端 未结 5 1319
既然无缘
既然无缘 2021-01-17 22:43

I\'m creating a leaflet map inside an Angular-cli project. Map tiles are stored locally in the \'assets\' folder because it\'s a raster map. The problem is when I\'ve many z

相关标签:
5条回答
  • 2021-01-17 22:51

    For those who get the same error, I solved the problem by changing global ng.cmd file.

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

    Copy/paste the following code into your ng.cmd.

    @IF EXIST "%~dp0\node.exe" (
      "%~dp0\node.exe" --max_old_space_size=8048 "%~dp0\node_modules\@angular\cli\bin\ng" %*
    ) ELSE (
      @SETLOCAL
      @SET PATHEXT=%PATHEXT:;.JS;=;%
      node --max_old_space_size=8048 "%~dp0\node_modules\@angular\cli\bin\ng" %*
    )
    
    0 讨论(0)
  • 2021-01-17 22:54

    You can add NODE_OPTIONS as a system variable. To set memory to 4 gigs,

    --max-old-space-size=4096

    Lots more info on this thread, they deserve the votes

    0 讨论(0)
  • 2021-01-17 23:04

    Add the below line to Package.json

    "aot": "node --max-old-space-size=8192 ./node_modules/@angular/cli/bin/ng 
    build --prod --aot"
    

    and try running with "npm run aot".

    It worked for me.

    0 讨论(0)
  • 2021-01-17 23:05

    Run the following command in terminal

    node --max_old_space_size=10048 ./node_modules/@angular/cli/bin/ng serve

    0 讨论(0)
  • 2021-01-17 23:08

    Add this line to package.json file.

    "build": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod"
    
    0 讨论(0)
提交回复
热议问题