当前位置: 首页 > 知识库问答 >
问题:

heroku中托管的React项目在打开时失败

齐成双
2023-03-14

因此,使用bitbucket管道向heroku部署了一个React项目,该项目运行良好,但现在似乎无法使heroku打开该项目时不使用我的Package.json中的脚本npm start。建议创建一个文件Procfile,它是一个txt文件,内部有have

Web:index.html

在我的WebPack中:

entry: {
    bundle: './src/index.js'
},
output: {
    publicPath : '/',
    path: path.resolve(__dirname,'build'),
    filename: '[name].[chunkhash].js'
},

和package.json中

 "scripts": {
    "heroku-prebuild": "npm install --only=dev",
    "clean": "rimraf build",
    "build": "npm run clean && webpack -p",
    "serve": "webpack-dev-server --progress --colors"
  },

在heroku日志中得到:

HEROKU[router]:at=error code=h10 desc=“App已崩溃”method=get path=“/”host=projectname.herokuapp.com request_id=a2bc33da-f938-4d7b-9395-b40442f9b2c0 fwd=“88.157.88.35”dyno=connect=service=status=503 bytes=protocol=https

HEROKU[router]:at=error code=h10 desc=“App已崩溃”method=get path=“/favicon.ico”host=projectname.herokuapp.com request_id=b2de2bdf-528e-4f97-9fe9-7f313e025ebd fwd=“88.157.88.35”dyno=connect=service=status=503 bytes=protocol=https

不使用create-react-app,如果可能,不想添加节点express以指向react项目https://blog.bitsrc.io/React-production-deployment-part-3-heroku-316319744885

那么我需要在procfile中指向build/index.html吗??或者是其他的方式,所有的例子都是关于create-react-app和node express....

共有1个答案

皇甫才良
2023-03-14

我们能够在下面的博客中找到解决方案,如所述,如果Procfile丢失,heroku默认运行npm start命令,或者在Procfile中添加行web:npmstart,如博客中所述,package.json中的start命令运行serve-s build,其中serve是一个包,以指向bundle和index.html文件所在的构建文件夹,现在它已经很好地工作了。Heroku应该有一个默认选项指向默认文件夹。但所有尝试都失败了...所以感谢@Bernard Bado和他的博客指出了解决方案。

 类似资料:
  • 本章介绍如何在GitHub上创建一个新项目,包括创建版本库及为项目设计主页等。 3.1. 创建新项目 3.2. 操作版本库 3.3. 公钥认证管理 3.4. 版本库钩子扩展 3.5. 建立主页

  • 项目管理 & 代码托管 Github [free to $] Codebase [$] Bitbucket [free to $] Unfuddle [$] Assembla [free to $]

  • 在上一节学习了如何建立GitHub的账户,接下来在建立自己的项目托管之前,先来看看别人是怎么做的。 在GitHub中搜索字符串“GotGit”,可以搜索到我建立的一个项目,项目地址是:https://github.com/gotgit/gotgit/。由上至下,GotGit项目首页可以分为如下几个区域。 区域一:项目概要介绍及版本库URL等。 项目GotGit托管在组织账号 gotgit 之下[1

  • > 其中:Build file'C:\users\documents\project\project_workspace\projectname\node_modules\react-native-reanimated\android\Build.gradle'行:69 错误:配置项目“:React-Native-Reanimated”时出现问题。 IOException:文件名、目录名或卷标语法

  • 但当我尝试打开一个URL时,它给出: 该代码适用于API级别28,但在API级别24中抛出以上错误。我搜索到类TracingController是在API level 28中引入的,我正在尝试在API 24中打开webview,但我不知道如何配置它以在API level 24中打开。 我的build.gradle文件: 任何关于如何打开WebView的提示,或者如何在API级别24中打开WebVi

  • 我不熟悉在VSO上使用npm构建。我得到了下面的错误,无法破译它。 我正在Visual Studio Online托管的生成控制器上使用新的脚本生成。 有人能帮忙吗?