前提・実現したいこと
Ruby on Rails でアプリを作成しローカル環境では正常に動作しました。
それをherokuをもちいてアップロードしたいです。
https://qiita.com/kazukimatsumoto/items/a0daa7281a3948701c39
を参考に操作を進めました。
発生している問題・エラーメッセージ
terminal
1git push heroku master
を実行すると
terminal
1remote: -----> Detecting rake tasks 2remote: -----> Preparing app for Rails asset pipeline 3remote: Running: rake assets:precompile 4remote: rake aborted! 5remote: Sprockets::Railtie::ManifestNeededError: Expected to find a manifest file in `app/assets/config/manifest.js` 6remote: But did not, please create this file and use it to link any assets that need 7remote: to be rendered by your app: 8remote: 9remote: Example: 10remote: //= link_tree ../images 11remote: //= link_directory ../javascripts .js 12remote: //= link_directory ../stylesheets .css 13remote: and restart your server 14remote: 15remote: For more information see: https://github.com/rails/sprockets/blob/070fc01947c111d35bb4c836e9bb71962a8e0595/UPGRADING.md#manifestjs 16 17(中略) 18 19remote: ! Precompiling assets failed. 20remote: ! 21remote: ! Push rejected, failed to compile Ruby app. 22remote: 23remote: ! Push failed 24remote: ! 25remote: ! ## Warning - The same version of this code has already been built: 54cb7a80eb8c20c1ec95267c9ae553c7f2a3d705 26remote: ! 27remote: ! We have detected that you have triggered a build from source code with version 54cb7a80eb8c20c1ec95267c9ae553c7f2a3d705 28remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch. 29remote: ! 30remote: ! If you are developing on a branch and deploying via git you must run: 31remote: ! 32remote: ! git push heroku <branchname>:main 33remote: ! 34remote: ! This article goes into details on the behavior: 35remote: ! https://devcenter.heroku.com/articles/duplicate-build-version 36remote: 37remote: Verifying deploy... 38remote: 39remote: ! Push rejected to <アプリ名>. 40remote: 41To https://git.heroku.com/<アプリ名>.git 42 ! [remote rejected] master -> master (pre-receive hook declined) 43error: failed to push some refs to 'https://git.heroku.com/<アプリ名>.git'
と表示され実行できません。
試したこと
多くのサイトに以下の一文を足すと良いと書かれていたので実行しました
config/environments/production.rbへの記述 config.assets.initialize_on_precompile = false
全体はこのようなコードです。
config/environments/production.rb内 require_relative "boot" require "rails/all" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module <アプリ名> class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 6.1 # Configuration for the application, engines, and railties goes here. # # These settings can be overridden in specific environments using the files # in config/environments, which are processed later. # # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") config.time_zone = 'Tokyo' #herokuの解決用 config.assets.initialize_on_precompile = false end end
怪しいのはターミナルのこのメッセージかなと思い、
terminal
1remote: Running: rake assets:precompile 2remote: rake aborted! 3remote: Sprockets::Railtie::ManifestNeededError: Expected to find a manifest file in `app/assets/config/manifest.js` 4remote: But did not, please create this file and use it to link any assets that need 5remote: to be rendered by your app: 6remote: 7remote: Example: 8remote: //= link_tree ../images 9remote: //= link_directory ../javascripts .js 10remote: //= link_directory ../stylesheets .css 11remote: and restart your server
とりあえずExampleで示されている通りに変えてrails s でサーバを再起動しました。
js
1app/assets/config/manifest.js内のコード 2 3//= link_tree ../images 4//= link_directory ../javascripts .js 5//= link_directory ../stylesheets .css 6
もともとは2行目の//= link_directory ../javascripts .js の記載がありませんでした。
他のサイトを参考に以下を実行すると
terminal
1$ RAILS_ENV=development bin/rails assets:precompile 2yarn install v1.22.10 3[1/4] ???? Resolving packages... 4[2/4] ???? Fetching packages... 5[3/4] ???? Linking dependencies... 6[4/4] ???? Building fresh packages... 7✨ Done in 2.54s. 8rails aborted! 9Sprockets::ArgumentError: link_directory argument must be a directory 10/app/assets/config/manifest.js:2 11Tasks: TOP => assets:precompile 12(See full trace by running task with --trace)
とでるのでapp/assets/config/manifest.js内のコードは変えないほうが良かったかなとも考えています。
補足情報(FW/ツールのバージョンなど)
VS codeのターミナルを使用しています。
あなたの回答
tips
プレビュー