我用过Angular 5
我尝试ng build --prod
显示此错误:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
我已经读过this和this并在-max_old_space_size
中更改了package.json
,但是没有再次在生产中显示以上错误。
有什么问题?怎么解决呢?是package.json的问题/>
package.json:
{
"name": "asd",
"version": "0.6.2",
"license": "MIT",
"angular-cli": {},
"scripts": {
"build:dev": "./node_modules/.bin/ng build",
"build:prod": "./node_modules/.bin/ng build --prod --aot=false",
"build:aot": "./node_modules/.bin/ng build --prod --aot",
"build:aot2": "node --max_old_space_size=4096 ./node_modules/.bin/ng build --prod --aot",
"build": "npm run build:dev",
"clean:dist": "npm run rimraf -- dist",
"clean:install": "npm set progress=false && npm install",
"clean:start": "npm start",
"clean": "npm cache clean && npm run rimraf -- node_modules doc coverage dist",
"e2e:live": "npm run e2e -- --elementExplorer",
"e2e": "npm run protractor",
"lint": "npm run tslint \"src/**/*.ts\"",
"prebuild:dev": "npm run clean:dist",
"prebuild:prod": "npm run clean:dist",
"preclean:install": "npm run clean",
"preclean:start": "npm run clean",
"protractor": "protractor",
"rimraf": "rimraf",
"server:dev": "./node_modules/.bin/ng serve",
"serve": "npm run server:dev",
"start": "npm run server:dev",
"test": "./node_modules/.bin/ng test",
"tslint": "tslint",
"typedoc": "typedoc",
"ng": "ng",
"pree2e": "webdriver-manager update --standalone false --gecko false"
},
"private": true,
....
}
答案 0 :(得分:3)
此时升级Angular无法解决问题(但将来可能会解决)。我在Windows计算机上也通过Angular 7和8项目获得了它。
看起来您可能需要更新package.json中的内存增加。 Here is a link似乎已经解决了很多人的问题,我认为您必须在节点模块中指定Angular CLI的路径。
代替
node --max_old_space_size=4096 ./node_modules/.bin/ng build --prod --aot
尝试
node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build --prod --aot
解决方案中的此路径看起来正确back to Angular 4。
答案 1 :(得分:1)
将node.js更新为12个版本
答案 2 :(得分:1)
export NODE_OPTIONS=--max-old-space-size=8192
这对我在 Linux 上有帮助。我在以下位置找到了这个解决方案: https://support.snyk.io/hc/en-us/articles/360002046418-JavaScript-heap-out-of-memory
答案 3 :(得分:0)
在cmd提示符下运行以下命令:
node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod
我相信这会解决您的问题。
答案 4 :(得分:0)
第一种方式:
运行方式:
node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve
其中8048是新的内存限制(以兆字节为单位)(默认为〜1500)。或将命令添加到package.json文件:
"build-serve": "node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve"
并以npm运行,运行build-serve
或另一种方式:Windows快速有效的解决方案
打开C:\ Users \ userName \%AppData%\ Roaming \ npm
将以下代码复制/粘贴到您的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" %*
)
答案 5 :(得分:0)
以上没有单一解决方案对我有用。但是,下面的组合解决了问题:
node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod