【问题标题】:Error for start script when trying to deploy Django-React with Heroku尝试使用 Heroku 部署 Django-React 时启动脚本出错
【发布时间】:2021-08-28 19:35:43
【问题描述】:

我正在尝试部署我的第一个应用程序,该应用程序使用 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 -

【问题讨论】:

  • 欢迎来到 Stack Overflow。请查看how-to-ask。您需要更具体地说明您遇到的问题或您的期望。添加代码以显示您到目前为止所做的事情或您在此过程中发现的错误非常重要。
  • 对不起,我不是故意含糊的。我用一些信息编辑了帖子。我以前从未与 Heroku 合作过,所以我真的不知道我是否包含了正确的信息。感谢您理解我是新来的。

标签: reactjs django heroku


【解决方案1】:

该错误表明 heroku 无法启动服务器。

我认为你没有安装 gunicorn 包。

  • pip install gunicorn

在settings.py中

 ALLOWED_HOSTS = ["127.0.0.1","localhost","YOUR_APP.herokuapp.com"]

【讨论】:

  • 谢谢你的回答,不是我的gunicorn问题,而是白噪声问题。将其更新为5.2.0 后,它就可以工作了。
猜你喜欢
  • 2019-04-03
  • 1970-01-01
  • 2020-06-07
  • 1970-01-01
  • 2021-05-16
  • 2022-01-25
  • 2018-05-26
  • 2023-03-22
相关资源
最近更新 更多