当使用HTML和JavaScript创建的网站无法在Heroku上部署时的解决方法

最近的情况汇报

我已成功转职为工程师。我在YouTube上分享有关想转职为工程师的人的信息。

我用HTML/JavaScript制作了一个用于学习的页面,但在将其部署到Heroku时遇到了问题,不过很容易解决,我将写下解决方法。

使用git push heroku master进行部署时失败了…

PS C:\Users\***\Desktop\***> git push heroku master
Enumerating objects: 372, done.
Counting objects: 100% (372/372), done.
Delta compression using up to 8 threads
Compressing objects: 100% (344/344), done.
Writing objects: 100% (372/372), 230.52 KiB | 2.59 MiB/s, done.
Total 372 (delta 111), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> App not compatible with buildpack: https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz
remote:
remote:  !     ERROR: Application not supported by 'heroku/nodejs' buildpack
remote:  !
remote:  !     The 'heroku/nodejs' buildpack is set on this application, but was
remote:  !     unable to detect a Node.js codebase.
remote:  !
remote:  !     A Node.js app on Heroku requires a 'package.json' at the root of
remote:  !     the directory structure.
remote:  !
remote:  !     If you are trying to deploy a Node.js application, ensure that this
remote:  !     file is present at the top level directory. This directory has the
remote:  !     following files:
remote:  !
remote:  !     If you are trying to deploy an application written in another
remote:  !     language, you need to change the list of buildpacks set on your
remote:  !     Heroku app using the 'heroku buildpacks' command.
remote:  !
remote:  !     For more information, refer to the following documentation:
remote:  !     https://devcenter.heroku.com/articles/buildpacks
remote:  !     https://devcenter.heroku.com/articles/nodejs-support#activation
remote:
remote:
remote:        More info: https://devcenter.heroku.com/articles/buildpacks#detection-failure
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to ***
remote:
To https://git.heroku.com/***.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/***/

虽然很长,但是如果在Heroku上设置了Node.js的Buildpack,似乎需要一个package.json文件。

简单来说,就是没有被识别为应用程序。

所以,实际制作并重新部署,却出现了应用错误…
这可能会陷入困境…

如果我能很容易地解决这个问题,我就不会发现这样的帖子了。

在将简单的HTML/CSS/JS部署到Heroku时遇到的问题。

原来如此,在根目录下创建package.json和index.php,然后在index.php中使用require_once引入index.html就可以了。
(意思是将其作为PHP应用程序部署)

解决方案 ‘àn)

在与index.html相同的层级下创建以下两个文件。

<?php include_once("index.html"); ?>
{}

提交代码后,再次使用git push heroku master推送至heroku。

PS /***> git push heroku master
remote:        https://***.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/***.git

部署成功!

虽然这不是一个应用程序,但还是要部署

我强烈推荐Heroku,因为它不需要服务器设置,可以轻松免费发布网页。

广告
将在 10 秒后关闭
bannerAds