我正试图在数字海洋远程ubuntu服务器上部署我的MERN应用程序。gitclone之后,我将npm安装到我的根文件夹、客户端文件夹和服务器文件夹中。但当我尝试从根文件夹运行npm-start时,只有服务器应用程序在运行,客户端出现了错误。因此,我将cd放入客户端文件夹,并尝试命令npm run build(我在本地机器上也这样做了,优化的构建成功创建(,但它在远程服务器上显示了以下错误
> client@0.1.0 build /home/nishant/apps/rentaporta/client
> react-scripts build
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.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the client@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/nishant/.npm/_logs/2020-10-27T05_22_30_755Z-debug.log
我删除了node_modules、package-lock.json,并尝试了npm-ci命令,但没有任何改进。我的文件夹结构是
root
client
server
下面是根文件夹中的package.json脚本
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"client-install": "npm install --prefix client",
"server-install": "npm install ---prefix server",
"server": "npm start --prefix server",
"client": "npm start --prefix client",
"build-client": "npm run build --prefix client",
"dev": "concurrently "npm run server" "npm run client"",
"start": "npm run server-install & concurrently "npm run build-client" "npm run server""
},
请有人帮帮我。如果你需要更多的解释,我准备根据需要提供更多的细节。
最后,我解决了这个问题。我的远程ubuntu服务器有1GB的内存,但没有交换内存。我使用命令sudo free-h,发现交换内存为0。所以,我关注了这篇文章(https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04)创建交换内存,最后,我的应用程序被部署了。
此外,cd到您的客户端文件夹中,并在终端-中运行此命令
$ export NODE_OPTIONS=--max-old-space-size=8192