Angular build compiler memory overflow "JavaScript heap out of memory" solution

When using angular build on the recent compilation packed encounter unexpected memory overflow, make a simple record

Compile given as follows ↓↓↓


 

Error message is very intuitive to note that memory overflow. What causes memory overflow it? The fundamental reason is nodejs default limits the maximum memory size can be used. nodejs V8 engine default limit memory usage on 64-bit machines does not exceed the maximum 1.7GB

Solutions can increase the memory size , modify package.json scripts in the script ↓

node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --prod
 1 "scripts": {
 2         "ng": "ng",
 3         "build-prod": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --prod",
 4         "start": "ng serve --host 0.0.0.0 --port 64862 -o   ",
 5         "build": "ng build --prod --build-optimizer",
 6         "test": "ng test",
 7         "lint": "npm run lint:ts && npm run lint:style",
 8         "e2e": "ng e2e",
 9         "analyze": "ng build --prod --build-optimizer --stats-json",
10         "test-coverage": "ng test --code-coverage --watch=false",
11         "lint:ts": "tslint -p src/tsconfig.app.json -c tslint.json 'src/**/*.ts'",
12         "lint:style": "stylelint \"{src}/**/*.less\" --syntax less",
13         "lint-staged": "lint-staged",
14         "tslint-check": "tslint-config-prettier-check ./tslint.json",
15         "hmr": "ng serve --host 0.0.0.0 --port 64862 --hmr"
16     }

 

然后重新运行npm run build-prod 编译成功!!!

Guess you like

Origin www.cnblogs.com/24klr/p/11262633.html