【问题标题】:How to deploy MERN stack app to GitHub and Heroku?如何将 MERN 堆栈应用程序部署到 GitHub 和 Heroku?
【发布时间】:2021-02-06 12:47:05
【问题描述】:

我已经使用 ReactJS 进行前端开发已经有一段时间了,我决定使用 MERN(MongoDB - Express - React - Node)将我的技能升级到全栈。我已成功开发 MERN 应用,但部署过程失败。

我尝试使用“从 GitHub 到 Heroku”的方法,您首先将所有内容上传到 GitHub,然后在 Heroku 上使用它。我什至无法将我的文件结构上传到 GitHub,所以我正在寻求帮助。

我想知道我的文件结构可能是错误的,所以这里有一些屏幕截图让你明白:

当我尝试上传到 GitHub 时,我收到以下警告:

warning: adding embedded git repository: client

跟进一堆提示......为什么会发生这种情况?我认为客户端和服务器都有单独的 .gitignore 文件,这可能是问题吗?

cd (to the directory where client and server are)
git init
git add .

此时我不断收到警告:

warning: adding embedded git repository: client
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint: 
hint:   git submodule add <url> client
hint: 
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint: 
hint:   git rm --cached client
hint: 
hint: See "git help submodule" for more information.

感谢您的帮助。

【问题讨论】:

  • 请提供minimal reproducible example,使用文本而不是屏幕截图。您是否尝试部署一两个存储库?一个应用还是两个?
  • 我正在尝试将两个文件(客户端和服务器)上传到一个 github 存储库。这两个文件都是我的应用程序的一部分 - 前端和后端。所以我试图只部署一个应用程序。
  • 我在问题的末尾添加了一些代码,这样你就可以看到我在做什么
  • 看来客户端目录已经是一个repo(例如,Create React App 默认创建一个)。你可以拥有多个.gitignore,这不是问题,但如果你想拥有一个仓库,你必须删除./client/.git/。然后你会遇到 Heroku 需要 Node buildpack 的 root 包文件的问题。如果您需要示例,我已经整理了一个示例全栈 JS 启动器,该启动器在(除其他外)Heroku here 上运行。
  • 你是对的,我使用了 git status 命令,似乎在我的客户端文件夹中 git 已经启动。我怎样才能删除它?我在任何地方都看不到它,我可以以某种方式 cd 进入它,但我不能使用 rm 删除 .git 文件。有什么方法可以停止该存储库?

标签: node.js reactjs github heroku mern


【解决方案1】:

我认为您使用了 create-react-app。 create-react-app 还会启动一个 git 存储库。

只需删除./client/.git,然后执行此操作。应该没问题。

cd ./client
rm -rf .git

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-26
    • 2020-09-08
    • 2018-11-08
    • 2021-03-03
    • 2021-09-14
    • 1970-01-01
    • 2020-08-19
    相关资源
    最近更新 更多