简体   繁体   English

无法将 React 应用程序部署到 Heroku - 无法部署

[英]Failed to Deploy React App to Heroku - Unable to Deploy

I have made a reactjs app.我制作了一个 reactjs 应用程序。 It's just the front-end.这只是前端。 So no nodes and databases are added.所以没有添加节点和数据库。 When I am trying to deploy it to Heroku, I am always facing the same error and couldn't resolve it.当我尝试将其部署到 Heroku 时,我总是遇到同样的错误并且无法解决。 I have added the logs and my package.json file.我已经添加了日志和我的 package.json 文件。

Heroku 日志 --tail 项目文件树

Package.json Package.json

{
  "name": "reactapp",
  "version": "0.1.0",
  "private": true,
  "engines": {
    "node": "12.17.0",
    "npm": "6.14.4"
  },
  "dependencies": {
    "@material-ui/core": "^4.11.0",
    "@material-ui/icons": "^4.9.1",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "bootstrap": "^4.5.0",
    "font-awesome": "^4.7.0",
    "react": "^16.13.1",
    "react-bootstrap": "^1.0.1",
    "react-dom": "^16.13.1",
    "react-helmet": "^6.1.0",
    "react-rating-stars-component": "^1.1.0",
    "react-router-dom": "^5.2.0",
    "react-script-tag": "^1.1.2",
    "react-scripts": "3.4.1",
    "reactstrap": "^8.5.1",
    "shards-react": "^1.0.3",
    "styled-components": "^5.1.1",
    "typescript": "^3.9.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {}
}

You're trying to start your app in production with react-scripts start which is actually meant for development.您正在尝试使用react-scripts start在生产中启动您的应用程序,这实际上是用于开发的。 To deploy a Create React App you need to build it and have a server that serves the build folder.要部署 Create React App,您需要构建它并拥有一个服务于构建文件夹的服务器。 That's because you're essentially building a static frontend application instead of a fully fledged backend API, which is what Heroku usually is for.那是因为您实际上是在构建 static 前端应用程序,而不是完全成熟的后端 API,这就是 Heroku 通常的用途。

If you want to deploy with Heroku, you need to use the Create React App buildpack .如果要使用 Heroku 进行部署,则需要使用Create React App buildpack You can add a buildpack to an existing dyno in the settings section of the UI or in using the heroku CLI:您可以在 UI 的设置部分或使用 heroku CLI 将 buildpack 添加到现有测功机:

heroku buildpacks:set mars/create-react-app -a APP_NAME

From next release onwards your app will use the buildpack.从下一个版本开始,您的应用程序将使用 buildpack。 For further explanation visit the buildpack repository linked above.如需进一步解释,请访问上面链接的 buildpack 存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM