我继承了一个应用程序,它已经开始变大了,我收到了错误消息CALL_AND_RETRY_LAST分配失败--内存中的JavaScript堆。根据我的研究,我需要设置节点参数max_old_space_size。
我目前正在运行Node7.8.0,所以看起来我不能使用环境变量NODE_OPTIONS,我尝试过设置它,但没有成功。我已经在下面粘贴了我现有的package.json文件,但是我不知道在脚本部分我可以把参数package.json放在哪里
当内存约为1.6GB时,节点进程通常会出现上述错误。
{
"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"
}
}更新8/27/2020:
我曾尝试采用以下建议的解决方案:
"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时收到以下错误:
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"发布于 2020-04-21 00:42:11
我就是这么用的:
"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%",
}https://stackoverflow.com/questions/61328714
复制相似问题