首页 > 解决方案 > 无法在服务器中“构建”项目

问题描述

我刚在香港买了一台全新的ecs.n4.small服务器1 vCPU 2 GiB

在服务器中,我 git 克隆了一个可以在本地构建好的 React 项目,然后我做yarnyarn 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在服务器中工作?

标签: reactjsnpmserver

解决方案


您的--max_old_space_size=8096构建脚本将节点的最大 ram 设置为 8 gig,但您的服务器只有 2 gig。当节点开始占用太多内存时,系统会因为贪婪而杀死它。

尝试移除标志或购买具有更多内存的容器。:)


推荐阅读