Nis*_*mar 5 web-deployment node.js reactjs digital-ocean devops
我正在尝试在数字海洋远程 ubuntu 服务器上部署我的 MERN 应用程序。在 git clone 之后,我将 npm install 安装到我的根文件夹、客户端文件夹和服务器文件夹。但是当我尝试从根文件夹运行 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
Run Code Online (Sandbox Code Playgroud)
我删除了 node_modules、package-lock.json,并尝试了 npm ci 命令,但没有任何改进。我的文件夹结构是
root
client
server
Run Code Online (Sandbox Code Playgroud)
下面是我在根文件夹中的 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\""
},
Run Code Online (Sandbox Code Playgroud)
请有人帮助我。如果您需要更多解释,我已准备好根据需要提供更多详细信息。
终于,我找到了问题所在。我的远程 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2117 次 |
| 最近记录: |