reactjs - 无法在服务器中“构建”项目
问题描述
我刚在香港买了一台全新的ecs.n4.small
服务器1 vCPU 2 GiB
。
在服务器中,我 git 克隆了一个可以在本地构建好的 React 项目,然后我做yarn
了yarn build
. 3分钟后,它返回:
yarn build
yarn run v1.22.4
$ react-scripts --max_old_space_size=8096 build
Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.
Creating an optimized production build...
The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process.
在/var/log/syslog
中,我发现:
May 1 08:34:45 AliYun kernel: [46379.316865] [25517] 0 25517 193946 6641 130 76 0 0 node
May 1 08:34:45 AliYun kernel: [46379.316867] [25538] 0 25538 1126 18 7 3 0 0 sh
May 1 08:34:45 AliYun kernel: [46379.316869] [25539] 0 25539 113703 1697 63 27 0 0 node
May 1 08:34:45 AliYun kernel: [46379.316871] [25546] 0 25546 629715 439566 6497 6041 0 0 node
May 1 08:34:45 AliYun kernel: [46379.316873] Out of memory: Kill process 25546 (node) score 856 or sacrifice child
May 1 08:34:45 AliYun kernel: [46379.317613] Killed process 25546 (node) total-vm:2518860kB, anon-rss:1757868kB, file-rss:396kB
May 1 08:35:01 AliYun CRON[25570]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
有谁知道我应该改变什么才能yarn build
在服务器中工作?
解决方案
您的--max_old_space_size=8096
构建脚本将节点的最大 ram 设置为 8 gig,但您的服务器只有 2 gig。当节点开始占用太多内存时,系统会因为贪婪而杀死它。
尝试移除标志或购买具有更多内存的容器。:)
推荐阅读
- angular - 角度 6 上的 firebase 错误
- java - firebase 身份验证期间的错误
- security - gflags full page heap 好像没有效果?
- python - Converting LabColor to sRGBColor in colormath gives invalid hex
- c# - 检查列表是否包含在字符串属性中?
- c# - c# WPF - SetZIndex UserControl 问题
- google-cloud-platform - Cloud Datastore GQL 中的 GEOPOINT 支持
- windows-installer - Docker Windows 容器中的 VSTS CLI
- python - 如何在循环python中编写具有多个字典的.json文件
- javascript - Javascript 中的 parseInt() 是如何工作的?