简体   繁体   English

推送到 Heroku 时未找到模块错误

[英]Module Not Found Error while Pushing to Heroku

I understand that this issue has been raised numerous times, but I have tried almost all solutions available with no success.我知道这个问题已被多次提出,但我尝试了几乎所有可用的解决方案,但均未成功。 The thing is that I am capable of deploying to GitHub pages with no problem, but Heroku mentions I have some routing issue.问题是我能够毫无问题地部署到 GitHub 页面,但 Heroku 提到我有一些路由问题。

After the recent issue whereby Heroku removed Github integration with Heroku, I have been having trouble pushing code.在最近 Heroku 删除 Github 与 Heroku 集成的问题之后,我在推送代码时遇到了麻烦。 Initially, my website worked fine, with automatic deployment via Github.最初,我的网站运行良好,通过 Github 自动部署。 However, when I try manually pushing via:但是,当我尝试通过以下方式手动推送时:

$ git add .
$ git commit -am "make it better"
$ git push heroku master

I am facing this error:我正面临这个错误:

Module not found: Error: Can't resolve './pages/MainPage' in '/tmp/build_8986ef5f/src'

I have tried removing this page, and the error will just change to another can't resolve path error.我已尝试删除此页面,该错误只会更改为另一个无法解决路径错误。

My file directory is:我的文件目录是:

- build
- node_modules
- public
- src
    - pages
        - MainPage.js
        - SecondPage.js
        - ...
    - App.js
    - index.js
.gitignore
package-lock.json
package.json

Within the App.js file, I import the library through a relative path via:在 App.js 文件中,我通过以下方式通过相对路径导入库:

import Home from './pages/MainPage';

Is there something wrong with my relative pathing?我的相对路径有问题吗? I have not changed the structure since deploying via Github so I don't know what's the error.自从通过 Github 部署以来,我没有更改结构,所以我不知道错误是什么。

I've found out the error.我发现了错误。 Apparently deploying to Github had resulted in some case-sensitive naming to go wrong.显然,部署到 Github 导致一些区分大小写的命名出错。 Eg although I was deploying it as MainPage, it was deployed as mainpage for some reason.例如,虽然我将它部署为 MainPage,但由于某种原因它被部署为 mainpage。

This had resulted in being unable to find the file path.这导致无法找到文件路径。

I used:我用了:

heroku run bash

To figure out the error of naming convention.找出命名约定的错误。 To fix it, I removed all affected folders with wrong casing deployment, committed changes, then readded them in and redeployed it.为了修复它,我删除了所有受影响的文件夹,其中的外壳部署错误,提交了更改,然后将它们读入并重新部署。 It worked after I did this.在我这样做之后它起作用了。

Thank you @dfwgwefewfwe!谢谢@dfwgwefewfwe! I don't have enough reputation to comment on their post, but it definitely fixed it for me.我没有足够的声誉来评论他们的帖子,但它确实为我解决了这个问题。

Just to add some extra information though for others that may be stuck with it:只是为其他可能被卡住的人添加一些额外的信息:

My issue was that I had some assets that were in folders such as我的问题是我有一些资产位于文件夹中,例如

Equipment
  /hands
    /gloves1.png
    /gloves2.png
  /feet
    /boots1.png
    /boots2.png

To make things more consistent, I just capitalized the first letters to be Hands and Feet为了使事情更加一致,我只是将第一个字母大写为 Hands and Feet

I ran that command我运行了那个命令

heroku run bash

and was able to find those folders that had been renamed, and they were still in their old version.并且能够找到那些已重命名的文件夹,它们仍处于旧版本。

So back on my local copy, I moved the whole Equipment folder to another location, removed any references to the assets in the code, and pushed that up to heroku.所以回到我的本地副本,我将整个 Equipment 文件夹移动到另一个位置,删除了代码中对资产的所有引用,并将其推送到 heroku。

Now the Equipment folder was removed on the server, then I was able to revert my last git commit and push exactly what I was trying to push before and it worked.现在设备文件夹已在服务器上删除,然后我能够恢复我的最后一次 git 提交并准确推送我之前尝试推送的内容并且它有效。

I hope that this helps someone else!我希望这对其他人有帮助!

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

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