Node.js Appveyor构建内存不足求助:Angular 2 AOT构建失败
I’ve run into this exact issue with Angular AOT builds on AppVeyor before—here’s how to properly fix the heap out of memory error by adding the Node.js memory flag in the right place:
The key mistake here is that --max-old-space-size (both hyphenated and underscore forms work for Node.js) is a Node.js runtime parameter, not an Angular CLI flag. You can’t pass it directly to ng build; you need to wrap the Angular CLI invocation with a node command that includes the memory flag first.
Option 1: Add the flag to your npm script (most reliable)
Update your package.json scripts to explicitly call Node with the memory limit before invoking the Angular CLI:
"scripts": { "build:aot": "node --max-old-space-size=4096 ./node_modules/@angular/cli/bin/ng build --aot" }
Then in your appveyor.yml, call this script instead of running ng build directly:
build_script: - npm run build:aot
This ensures the memory flag is applied to the Node process running the CLI, not ignored by Angular.
Option 2: Directly in AppVeyor’s build command
If you prefer not to modify your npm scripts, you can run the wrapped command directly in appveyor.yml:
build_script: - node --max-old-space-size=4096 ./node_modules/@angular/cli/bin/ng build --aot
Avoid the common pitfall of adding the flag to the ng build arguments—Angular CLI won’t recognize it, and Node will never receive the parameter to increase the heap size.
Option 3: Fixing PowerShell script attempts
If you tried adding this in a PowerShell script earlier, make sure you’re invoking Node correctly (no extra syntax that breaks the parameter passing):
node --max-old-space-size=4096 ./node_modules/@angular/cli/bin/ng build --aot
Stick to the standard node [flags] [cli-script-path] [cli-flags] structure, and the memory limit will be applied as expected.
Quick tip: Adjust the memory value
Start with 4096 (4GB) which is usually enough for most Angular AOT builds. If you still run into issues, you can increase it to 8192 (8GB), but keep in mind AppVeyor’s default Windows VMs have 2GB of physical memory—Node will use virtual memory if needed, but 4GB is a safe starting point.
内容的提问来源于stack exchange,提问作者dudewad

