Open zlibo2019 opened 5 years ago
请问你后面解决了吗,我也是设置了不起作用呢
建个批处理文件,内容如下: @echo off cmd /c setx NODE_OPTIONS --max_old_space_size=4096 set nodevars = "C:\Program Files\nodejs\nodevars.bat" cmd /c %nodevars%&&npm run dev
启动程序,就可以把你当前运行的程序内存固定设置为4096
------------------ 原始邮件 ------------------ 发件人: "endel/increase-memory-limit" <notifications@github.com>; 发送时间: 2020年12月18日(星期五) 下午4:23 收件人: "endel/increase-memory-limit"<increase-memory-limit@noreply.github.com>; 抄送: "&&东子&&"<83433430@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [endel/increase-memory-limit] 为什么我设置一直不起作用 (#26)
请问你后面解决了吗,我也是设置了不起作用呢
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
I think the issue here is that the variable gets set during the first execution part, being: cross-env increase-memory-limit
. Then the next script (npm run dev) executes egg-bin dev -r egg-ts-helper/register
.
The variable is never hoisted over to the other script execution. Logging it in the console would result in undefined.
{
"name": "memory-limit",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "node main.js",
"start": "cross-env LIMIT=5444 powershell -Command \"increase-memory-limit; if ($?) { npm run dev }\""
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"cross-env": "^5.2.0",
"increase-memory-limit": "^1.0.6"
}
}
console.log(process.env.LIMIT);
The reason the above works is because it attaches both script executions to the same Powershell instance. That means the environment variable will live in both scripts and should therefor not be undefined anymore.
"scripts": { "start": "egg-scripts start --daemon --title=egg-server-weds-node-edu", "stop": "egg-scripts stop --title=egg-server-weds-node-edu", "dev": "egg-bin dev -r egg-ts-helper/register", "debug": "egg-bin debug -r egg-ts-helper/register", "test-local": "egg-bin test -r egg-ts-helper/register", "test": "npm run lint -- --fix && npm run test-local", "cov": "egg-bin cov -r egg-ts-helper/register", "tsc": "ets && tsc -p tsconfig.json", "ci": "npm run lint && npm run cov && npm run tsc", "autod": "autod", "lint": "tslint --project . -c tslint.json", "clean": "ets clean", "fix-memory-limit": "cross-env increase-memory-limit" }, "dependencies": { "6.0.0": "^1.0.1", "canvas": "^2.4.1", "cross-env": "^5.2.0", "egg": "^2.6.1", "egg-cors": "^2.1.2", "egg-logger": "^2.4.1", "egg-mq": "^0.1.0", "egg-redis": "^2.3.0", "egg-scripts": "^2.6.0", "egg-sequelize": "^4.1.0", "egg-session": "^3.1.0", "egg-socket.io": "^4.1.5", "formstream": "^1.1.0", "increase-memory-limit": "^1.0.7", "install": "^0.12.2", "jsdom": "^14.0.0", "log4js": "^4.4.0", "npm": "^6.5.0", "sequelize": "^5.8.9", "tedious": "^5.0.0" },
执行了一遍 npm run fix-memory-limit命令 然后npm run dev 启动项目做测试,仍然在内存用了1.5G左右就会报FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory