【问题标题】:Need to increase Node max_old_space_size via my existing package.json需要通过我现有的 package.json 增加节点 max_old_space_size
【发布时间】:2020-08-03 07:47:29
【问题描述】:

我继承的应用程序已经开始变大,我收到错误消息 CALL_AND_RETRY_LAST 分配失败 - JavaScript 堆内存不足。根据我的研究,我需要设置节点参数 max_old_space_size。

我目前正在运行 Node 7.8.0,因此我无法使用环境变量 NODE_OPTIONS,我尝试设置它但没有运气。我在下面粘贴了我现有的 package.json 文件,但我不知道在脚本部分中我可以放置参数 --max_old_space_size=2048

当内存达到 1.6 GB 左右时,节点进程通常会因上述错误而崩溃

{
 "scripts": {
"lint": "tslint --exclude=node_modules/** **/*.ts",
"generate:client": "ts-node ./swagger/generate-client.ts --baseApiUrl=http://localhost:5003",
"generate:client:prod": "ts-node ./swagger/generate-client.ts --baseApiUrl=%API_URL%",
"start": "npm run clean:dist && npm run generate:client && webpack -w",
"clean:dist": "rimraf ./wwwroot/*",
"build": "npm run clean:dist && npm run generate:client:prod && webpack -p"
},
"dependencies": {
"@types/googlemaps": "^3.26.1",
"@types/handlebars": "^4.0.31",
"@types/node": "^7.0.5",
"@types/react": "^15.0.34",
"@types/react-dom": "^15.5.1",
"@types/react-router": "^3.0.3",
"@types/superagent": "^2.0.36",
"@types/yargs": "^6.6.0",
"assets-webpack-plugin": "^3.5.1",
"css-loader": "^0.26.1",
"extract-text-webpack-plugin": "2.1.2",
"file-loader": "^0.10.0",
"google-map-react": "^0.22.3",
"handlebars": "^4.0.6",
"mobx": "^3.1.0",
"mobx-react": "^4.1.0",
"moment": "^2.17.1",
"node-sass": "^4.5.0",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-resize-observer": "^0.1.0",
"react-router": "^3.0.2",
"rimraf": "^2.6.1",
"sass-loader": "^6.0.1",
"style-loader": "^0.13.1",
"superagent": "^3.4.4",
"ts-loader": "^2.2.2",
"ts-node": "^3.1.0",
"tslint": "^4.4.2",
"tslint-loader": "^3.5.3",
"tslint-react": "^3.0.0",
"typescript": "^2.4.1",
"url-loader": "^0.5.7",
"webpack": "^3.1.0",
"webpack-md5-hash": "^0.0.5",
"yargs": "^6.6.0"
}
}

2020 年 8 月 27 日更新:

我已尝试使用以下建议的解决方案:

"scripts": {
"high-memory": "node --max_old_space_size=2048 ./node_modules/.bin/ts-node",
"generate:client": "npm run high-memory -- ./swagger/generate-client.ts --baseApiUrl=http://localhost:5003",
"generate:client:prod": "npm run high-memory -- ./swagger/generate-client.ts --baseApiUrl=%API_URL%",

}

运行 npm start 时收到以下错误:

C:\Projects\Twiddy\TwiddyOps\Web\node_modules\.bin\ts-node:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:423:7)
at startup (bootstrap_node.js:147:9)

Tell the author that this fails on your system:
npm ERR!     node --max_old_space_size=2048 ./node_modules/.bin/ts-node 
"./swagger/generate-client.ts" "--baseApiUrl=http://localhost:5003"

【问题讨论】:

    标签: node.js npm package.json npm-scripts


    【解决方案1】:

    我就是这么用的:

    "scripts": {
      "high-memory": "node --max_old_space_size=2048 ./node_modules/.bin/ts-node",
      "generate:client": "npm run high-memory -- ./swagger/generate-client.ts --baseApiUrl=http://localhost:5003",
      "generate:client:prod": "npm run high-memory -- ./swagger/generate-client.ts --baseApiUrl=%API_URL%",
    }
    

    【讨论】:

    • 我要删除脚本部分的其他命令吗?启动、构建、lint?或者只是添加高内存并更新生成?
    • 我已经进行了更新并收到了我在上面添加的以下错误
    • 完美配合node --max_old_space_size=2048 ./node_modules/.bin/ts-node xxxxx.ts,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2018-01-22
    • 1970-01-01
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多