【问题标题】:Rails 6 assets precompile failedRails 6 资产预编译失败
【发布时间】:2020-11-12 08:46:36
【问题描述】:

资产预编译失败。我试过了

$ RAILS_ENV=production bundle exec rake assets:precompile

它仍然无法正常工作。

这就是我得到的

remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote:
remote:  !     Push failed
remote:  !
remote:  ! ## Warning - The same version of this code has already been built: 80f7792c62f7678693d5b0a156516502662ee0ef
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 80f7792c62f7678693d5b0a156516502662ee0ef
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku <branchname>:main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to online-edukation.
remote:
To https://git.heroku.com/online-edukation.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/online-edukation.git'

请问是什么原因?

【问题讨论】:

  • 要检查的几件事 - 确保你在 master 分支上,并确保你首先完成了 git pull
  • 好的,谢谢。似乎事实并非如此。 ModuleNotFoundError: Module not found: Error: Can't resolve 'stylesheets/application.scss' in '/tmp/build_35bb4e62/app/javascript/packs' 这是错误
  • 尝试git pushheroku master -f强制推送

标签: ruby-on-rails ruby-on-rails-6


【解决方案1】:

这里有几件事您应该研究一下。 Heroku cli 中并不总是清楚地显示错误。这可能是一些事情,例如凭据,或者您没有正确推送到heroku。在您执行此操作之前,请检查您的 heroku 错误日志(在您的 heroku 仪表板中。)或 run heroku logs,您会惊讶地发现那里的内容。

首先确保在推送到 heroku 之前在本地机器上预编译资产。所以也许是这样的。

创建一个新分支并确保您当前的工作安全地提交到您的 master 或任何一个分支中。

git checkout -b test_heroku

现在你可以用这个分支做你想做的事了。让我们测试一些东西。 如果您使用 fb 应用程序、stripe 或 twillio 或任何其他第三方供应商,请去删除您应用程序中的所有 Rails.application.credentials 对象。请用测试密钥(不是真正的密钥)替换这些对象。例如 stripe 有测试模式键,FB 也有,只需替换它们并在此测试分支中销毁 config/credentials.yml.enc and config/master.key

# Make sure you remove `Rails.application.credentials` objects and replace them with test credentials in your files such as stripe.rb or twillio.rb etc..

rake assets:precompile
git add . 

git commit -m "testing"
git push --set-upstream origin test_heroku

请注意,您以后可以随时删除此 test_heroku git 分支。我只是建议这样做,以便您可以跟踪您正在进行的事件/更改的进度,以使其发挥作用。然后在此之后您可以创建一个新分支或修改主分支。

git push heroku test_heroku:main

如果这不起作用,您可以尝试

git push heroku test_heroku:main --force 

你可以使用--force,没问题。除非您希望新的 Heroku 实例将测试分支部署到新服务器。不同的主题。

无论如何,只是让你知道,如果你现在推送到 heroku,你应该没问题,如果这是由于秘密凭据配置错误或事故导致的预编译问题,它应该可以工作。

如果可行,请删除您的 git heroku_test 分支,修复错误并再次执行。

如果这是凭据的预编译问题(因为我在您的问题中看不到错误日志。)我建议您在此处查看此问题。对许多从 Rails.application.credentials 对象获取 NoMethodError: undefined method '[]' for nil:NilClass 的人来说,这似乎是个问题 https://github.com/rails/rails/issues/32947

【讨论】:

    猜你喜欢
    • 2021-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 2020-11-17
    • 2014-06-27
    相关资源
    最近更新 更多