-------如果未解决,请尝试以下第2步------------- 2)只需将Node版本更新到最新版本即可解决此问题。
-------如果未解决,请尝试以下第3步-------------
3)只需在Windows终端中运行此命令。
set NODE_OPTIONS=--max_old_space_size=4096
node_modules
文件夹npm install
对于我来说,我的语法错误(未显示出来)导致了这个错误。
import { async } from '../../../../public/js/app'
。不知道为什么会出现这种情况,你刚刚帮我节省了好几个小时! - Dale Ryannode --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build --baseHref=/baseUrl/ --prod=true
在我的情况下,添加参数--build-optimizer
解决了问题:
node --max_old_space_size = 4096 ./node_modules/@angular/cli/bin/ng build --prod --build-optimizer
我不确定为什么只添加--build-optimizer
就可以解决问题,但根据Angular文档,它应该与启用预编译(AOT)编译一起使用,因此更新后的命令应该如下:
--build-optimizer=true --aot=true
将以下这一行
"start": "ng serve -o --port 4300 --configuration=en"
替换为
"start": "node --max_old_space_size=5096 node_modules/@angular/cli/bin/ng serve -o --port 4300 --configuration=en"
注意:
port--4300不是固定值,取决于您选择的端口。
--max_old_space_size=5096也不是固定值; 可以是任何值:1024,2048,4096等。
NODE_OPTIONS
没有起作用,我猜测是因为Visual Studio使用了一个新的进程或者其他原因。将更改硬编码到我的package.json scripts
块中解决了问题。 - user101289我在Angular上面也遇到了同样的问题。然后我写了以下代码
"serve": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve"
package.json
的脚本中来解决。运行项目时,请使用以下命令:npm run serve
npm run serve
- @PeterSmith - Ali Alizade运行以下命令:
export NODE_OPTIONS="--max-old-space-size=2048"
检查您目前的使用量:
> node
> v8.getHeapStatistics()
{
total_heap_size: 6049792,
total_heap_size_executable: 524288,
total_physical_size: 5477720,
total_available_size: 1094444024,
used_heap_size: 4141728,
heap_size_limit: 1098907648,
malloced_memory: 8192,
peak_malloced_memory: 582752,
does_zap_garbage: 0,
number_of_native_contexts: 2,
number_of_detached_contexts: 0
}
然后是 heap_size_limit: 1098907648
node --max_old_space_size=8000 node_modules/@angular/cli/bin/ng serve --prod --port=4202
我用终端执行了下面的命令来解决这个问题,而不是使用 ng build
命令。
node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod
然后执行 ng serve
命令。
这是我的终端显示效果。
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS D:\ProjectPath\Project1> node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod
--prod
已经被弃用,请使用 --configuration production
代替。 - DFSFOT