如何解决npm run build在本地计算机上工作正常,但在远程ubuntu服务器上显示错误
我正在尝试将我的MERN应用程序部署在数字海洋远程ubuntu服务器上。 git clone之后,我将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)创建交换内存,最后,我的应用程序得到部署。
您也可以按照他的建议https://github.com/facebook/create-react-app/issues/3862#issuecomment-358969136
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。