reactjs - 尝试使用 Heroku 部署 Django-React 时启动脚本出错
问题描述
我正在尝试部署我的第一个应用程序,该应用程序具有 django 作为后端并为前端做出反应(使用 create-react-app)。我遵循了一些教程中的步骤,并设法让我的部署构建运行,但我收到 npm start 错误。我似乎找不到任何解决方案,任何帮助都会受到欢迎。
2021-06-11T21:48:08.784605+00:00 heroku[web.1]: State changed from crashed to starting
2021-06-11T21:48:22.000000+00:00 app[api]: Build succeeded
2021-06-11T21:48:25.830113+00:00 heroku[web.1]: Starting process with command `npm start`
2021-06-11T21:48:28.292792+00:00 app[web.1]:
2021-06-11T21:48:28.292815+00:00 app[web.1]: > ui@0.1.0 start /app
2021-06-11T21:48:28.292815+00:00 app[web.1]: > serve -s build
2021-06-11T21:48:28.292815+00:00 app[web.1]:
2021-06-11T21:48:28.297425+00:00 app[web.1]: sh: 1: serve: not found
2021-06-11T21:48:28.304774+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-06-11T21:48:28.305084+00:00 app[web.1]: npm ERR! syscall spawn
2021-06-11T21:48:28.305267+00:00 app[web.1]: npm ERR! file sh
2021-06-11T21:48:28.305429+00:00 app[web.1]: npm ERR! errno ENOENT
2021-06-11T21:48:28.309100+00:00 app[web.1]: npm ERR! ui@0.1.0 start: `serve -s build`
2021-06-11T21:48:28.309179+00:00 app[web.1]: npm ERR! spawn ENOENT
2021-06-11T21:48:28.309293+00:00 app[web.1]: npm ERR!
2021-06-11T21:48:28.309384+00:00 app[web.1]: npm ERR! Failed at the ui@0.1.0 start script.
2021-06-11T21:48:28.309470+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-06-11T21:48:28.315822+00:00 app[web.1]:
2021-06-11T21:48:28.316160+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-06-11T21:48:28.316161+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-06-11T21_48_28_310Z-debug.log
2021-06-11T21:48:28.376386+00:00 heroku[web.1]: Process exited with status 1
2021-06-11T21:48:28.543859+00:00 heroku[web.1]: State changed from starting to crashed
2021-06-11T21:50:15.500360+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=taby-bt.herokuapp.com request_id=3c84bb9a-a59b-489c-9d9d-19c886d42c72 fwd="5.15.164.88" dyno= connect= service= status=503 bytes= protocol=http
2021-06-11T21:50:16.200509+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=taby-bt.herokuapp.com request_id=1d44fdaf-4dcd-4f91-a28f-93e19c3fd9ca fwd="5.15.164.88" dyno= connect= service= status=503 bytes= protocol=http
2021-06-11T21:51:16.423492+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=taby-bt.herokuapp.com request_id=5d78951d-6a1f-45cd-8835-6b52b770e878 fwd="5.15.164.88" dyno= connect= service= status=503 bytes= protocol=http
2021-06-11T21:51:17.062971+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=taby-bt.herokuapp.com request_id=d79908e7-f51b-4e69-8563-17aa1aff8792 fwd="5.15.164.88" dyno= connect= service= status=503 bytes= protocol=http
在我的 settings.py 我有这个:
STATIC_URL = '/static/'
STATICFILES_DIRS =[
os.path.join(BASE_DIR,"build/static")
]
STATIC_ROOT = os.path.join(BASE_DIR,'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
在 package.json 我有这些:
"engines": {
"node": "15.5.1",
"npm": "6.14.11"
}
"scripts": {
"dev": "react-scripts start",
"start": "serve -s build",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"postinstall": "npm run build"
},
我的 Procfile 看起来像这样
release:python manage.py migrate
web:gunicorn chatbot.wsgi --log-file -
解决方案
该错误表明 heroku 无法启动服务器。
我想你没有安装 gunicorn 包。
- pip 安装 gunicorn
并在 settings.py
ALLOWED_HOSTS = ["127.0.0.1","localhost","YOUR_APP.herokuapp.com"]
推荐阅读
- linux - 如何设计对 nanomsg 套接字和 tty 或 Netlink 的异步处理?
- c# - 刷新 DataSource Master-Detail XtraGrid
- python - nargs='?' 当两个 pos 参数被一个 opt 参数分割时不起作用,为什么?
- javascript - 单击时更改 div 的内容(图标)
- java - 一次在 SQLite 中插入多行
- inno-setup - 在特定位置浏览和提取 zip 文件的 inno 设置
- node.js - 无法从其他计算机访问 macOS High Sierra 上的 Nodejs/Express 服务器
- javascript - 对组件属性做出等待等待
- android - 在我的 Firebase 帐户中保存实时数据库时出错
- html - ionic 3 中的聊天界面