【问题标题】:React components not rendering on Heroku反应组件不在 Heroku 上渲染
【发布时间】:2022-01-11 22:02:26
【问题描述】:

使用 react-rails gem 创建了一个 react rails 应用程序,但是当上传到 heroku 时,react 组件都丢失了。不过,它在我的本地服务器上运行良好。这是 package.json 文件,以防我错过任何东西。任何帮助将不胜感激!

    {
  "name": "my_app",
  "private": true,
  "dependencies": {
    "@babel/preset-react": "^7.7.4",
    "@rails/actioncable": "^6.0.0",
    "@rails/activestorage": "^6.0.0",
    "@rails/ujs": "^6.0.0",
    "@rails/webpacker": "^4.2.0",
    "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
    "bootstrap": "^4.4.1",
    "jquery": "^3.4.1",
    "popper.js": "^1.16.0",
    "prop-types": "^15.7.2",
    "react": "^16.12.0",
    "react-bootstrap": "^1.0.0-beta.16",
    "react-dom": "^16.12.0",
    "react-redux": "^7.1.3",
    "react-router-dom": "^5.1.2",
    "react_ujs": "^2.6.0",
    "redux": "^4.0.5",
    "redux-thunk": "^2.3.0",
    "turbolinks": "^5.2.0"
  },
  "version": "0.1.0",
  "devDependencies": {
    "@types/react-redux": "^7.1.6",
    "webpack-dev-server": "^3.9.0"
  }
}

【问题讨论】:

  • 您的浏览器控制台有错误吗?
  • @morissetcl nope 控制台上的一切似乎都很好,但 bootstrap/react/redux 组件没有出现

标签: ruby-on-rails reactjs heroku


【解决方案1】:

是的,您错过了设置主页重定向组件的位置,因此需要在构建项目后设置主页

{
  "name": "my_app",
  "private": true,
  "homepage":"/build" or "/path of your project build" ,
  "dependencies": {
    "@babel/preset-react": "^7.7.4",
    "@rails/actioncable": "^6.0.0",
    "@rails/activestorage": "^6.0.0",
    "@rails/ujs": "^6.0.0",
    "@rails/webpacker": "^4.2.0",
    "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
    "bootstrap": "^4.4.1",
    "jquery": "^3.4.1",
    "popper.js": "^1.16.0",
    "prop-types": "^15.7.2",
    "react": "^16.12.0",
    "react-bootstrap": "^1.0.0-beta.16",
    "react-dom": "^16.12.0",
    "react-redux": "^7.1.3",
    "react-router-dom": "^5.1.2",
    "react_ujs": "^2.6.0",
    "redux": "^4.0.5",
    "redux-thunk": "^2.3.0",
    "turbolinks": "^5.2.0"
  },
  "version": "0.1.0",
  "devDependencies": {
    "@types/react-redux": "^7.1.6",
    "webpack-dev-server": "^3.9.0"
  }
}

在部署 react 项目时需要主页。

【讨论】:

  • 我添加了主页但仍然是同样的问题,大部分反应和引导的东西都不见了
  • 捆绑文件中是否缺少这些?
  • 我认为可能是因为 buildpack
【解决方案2】:

只需尝试重新加载页面,Ctrl+Shift+R

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2016-11-15
  • 2021-06-04
  • 1970-01-01
  • 2020-03-08
  • 2020-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多