簡體   English   中英

Rails 6 資產預編譯失敗

[英]Rails 6 assets precompile failed

資產預編譯失敗。 我試過了

$ 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'

請問是什么原因?

這里有幾件事你應該研究一下。 錯誤並不總是清楚地顯示在 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 分支,修復錯誤並再次執行。

如果這是憑據的預編譯問題(因為我看不到您問題中的錯誤日志。)我建議您在此處查看此問題。 對於許多人來說,這似乎是一個問題,因為NoMethodError: undefined method '[]' for nil:NilClass from Rails.application.credentials 對象https://github.com/rails/rails/issues/32947

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM