I typically make updates to my production Ruby on Rails application and today I updated some security vulnerabilities with gem files, pushed them to my Github repo and then did a git push heroku master and received the following errors:
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: rake aborted!
remote: Devise.secret_key was not set. Please add the following to your Devise initializer:
remote:
remote: config.secret_key = '<hash>'
remote:
remote: Please ensure you restarted your application after installing Devise or setting the key....
remote: !
remote: ! Precompiling assets failed.
remote: !
Not sure if there is a connection between actionview -v 5.1.6.2 that I recently updated to and this error.
Open config/initializers/devise.rb file
it contain line
config.secret_key = 'xxxxxxxxxxxxxx'
If you find this line is commented, uncomment in. If it don't have any secret key find your secret key by running rake secret.
Best place to put your secret_key is enviornment variables. So try change line in devise.rb file like below.
config.secret_key = Rails.application.credentials.secret_key_base
Open config/secrets.rb file
production:
secret_key_base: ENV['DEVISE_SECRET_KEY']
In Heroku you can set DEVISE_SECRET_KEY in config variables.
Related
I am trying to upload my web app on heroku, but the following error occurs.
(I'm coding with cloud 9 IDE)
$ git push heroku master
.....
remote: -----> Installing node-v10.14.1-linux-x64
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: Yarn executable was not detected in the system.
remote: Download Yarn at https://yarnpkg.com/en/docs/install
remote: I, [2019-05-22T02:13:47.373334 #1766] INFO -- : Writing
/tmp/build_fcc84922ee6a02bfc05a163c871d0548/public/assets/noimage-
3aa3997354b4e9c37f379deb61626f55ade493078d1b42dcefe4a3ccbed34106.jpg
remote: rake aborted!
remote: ExecJS::RuntimeError: SyntaxError: Unexpected character '`'
remote: JS_Parse_Error.get ((execjs):3538:621)
remote: (execjs):4060:48
remote: (execjs):1:102
.....
remote: !
remote: ! Precompiling assets failed.
remote: !
remote: ! Push rejected, failed to compile Ruby app.
First of all, It says that "there Yarn executable was not detected in the system", but it is properly downloaded if I check it with yarn -v.
Also, ExecJS :: RuntimeError: SyntaxError: Unexpected character '`' error seems to be that es6 is not recognized, as a solution
config.assets.js_compressor =: uglifier
config.assets.js_compressor = Uglifier.new (harmony: true)
Changed to This seems to be able to read es6. But the above error still persists.
Also, if I run 'rake assets: precompile RAILS_ENV = production' on the console, it runs normally without error.
Thanks.
Try to add this gem in your gem file.
gem 'therubyracer'
Try this link:
Syntax error when deploying Rails app to Heroku: ExecJS::RuntimeError: SyntaxError: Unexpected character
config.assets.js_compressor =: uglifier
=: uglifier
space between : and uglifier?
should be = :uglifier
and try to use precompile command without string RAILS_ENV = production
because Heroku installs production mode by default. if I'm not mistaken
Try this, Go to heroku dashboard on their website, select your app, click on the gear icon (the settings), scroll down until you see “build packs” add ruby and nodejs buildpacks, and make sure the order is that that nodejs comes first in the list, and then ruby (from top to bottom).
If that doesn’t work, can you clarify how you are triggering the compilation of your JS?
Explanation: I’ve seen this error before(with npm, not yarn), essentially you want herokus nodejs buildpack to take care of JS compiling, the one rails has built in seems to not be compatible with their system.
When I put $git push heroku master, I got an argument error:
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: ArgumentError: secret_key_base for production environment must be a type of String
remote: /tmp/build_19076210a01025325310b08d032af424/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:583:invalidate_secret_key_base'
remote: /tmp/build_19076210a01025325310b08d032af424/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:432:in secret_key_base'
remote: /tmp/build_19076210a01025325310b08d032af424/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:176:inkey_generator'
remote: /tmp/build_19076210a01025325310b08d032af424/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:205:in `message_verifier'
.......................
My Rails version is 5.2 and which has new encrypt system filed in config/credentials.yml.enc. I guess this configuration makes this heroku error.
No one has this question and describe how to solve this error.
Could you please help me how to solve this error? Thanks.
https://waiyanyoon.com/deploying-rails-5-2-applications-with-encrypted-credentials-using-capistrano/
also before pushing to heroku try to compile assets in PRODUCTION mode locally to see if everything works.
I'm using dotenv to store environment variables and ever since I include it in the gemfile I cannot push it to heroku. I'm getting the following error:-
remote: -----> Installing node-v6.10.0-linux-x64
remote: -----> Detecting rake tasks
remote: sh: 2: Syntax error: Unterminated quoted string
remote: sh: 2: Syntax error: Unterminated quoted string
remote: !
remote: ! Could not detect rake tasks
remote: ! ensure you can run `$ bundle exec rake -P` against your app
remote: ! and using the production group of your Gemfile.
remote: ! rake aborted!
remote: ! NameError: uninitialized constant Dotenv
remote: ! /tmp/build_5437bc300afb80cfa46b1111bb960f46/config/application.rb:17:in `<top (required)>'
remote: ! /tmp/build_5437bc300afb80cfa46b1111bb960f46/Rakefile:4:in `require_relative'
remote: ! /tmp/build_5437bc300afb80cfa46b1111bb960f46/Rakefile:4:in `<top (required)>'
This is how I'm including dotenv in my gemfile:-
gem 'dotenv-rails', :require => 'dotenv/rails-now'
I have tried adding the following in the application.rb file as well:-
Bundler.require(*Rails.groups)
Dotenv::Railtie.load
HOSTNAME = ENV['HOSTNAME']
still doesn't work.
I don't know if those two lines that say "unterminated quoted string" could be some unrelated issue leading to the dotenv not loading. I looked it up and checked heroku config to see if there was something amiss in the variables but they all seem fine. I was able to push before I added the dotenv to gemfile.
I tried running bundle install, restarting server, deleting gemfile.lock and running bundle install and I looked this issue up on here and tried solutions suggested in Can't push to Heroku because of DOTENV uninitialized constant error
Still no luck.
PS - I'm trying to implement recaptcha and it is suggested best practice to use dotenv to store the site_key and secret_key for recaptcha as env vars. Hence I'm trying to get this to work.
I faced the same issue and was able to solve it with a following.
1) Add dotenv-rails in the Gemfile only for specific environments:
# Gemfile
group :development, :test do
gem 'dotenv-rails'
end
2) And run Dotenv stuff only if the environment matches your Gemfile group:
# config/application.rb
Bundler.require(*Rails.groups)
if ['development', 'test'].include? ENV['RAILS_ENV']
Dotenv::Railtie.load
end
Try adding the gem to the production group.
group :production do
gem 'dotenv-rails'
end
I am working through the Rails 4 In Action Book. I am on chapter 13: Deployment, page 457 where you push your code up to heroku:
git push heroku master
It appears to successfully grab all the needed gems as it gets to this part:
remote: Bundle complete! 27 Gemfile dependencies, 90 gems now installed.
remote: Gems in the groups development and test were not installed.
remote: Bundled gems are installed into ./vendor/bundle.
remote: Bundle completed (29.18s)
remote: Cleaning up the bundler cache
But then right after that it blows up and says this:
remote: -----> Detecting rake tasks
remote: sh: 2: Syntax error: Unterminated quoted string
remote: sh: 2: Syntax error: Unterminated quoted string
remote: !
remote: ! Could not detect rake tasks
remote: ! ensure you can run `$ bundle exec rake -P` against your app
remote: ! and using the production group of your Gemfile.
remote: ! rake aborted!
remote: ! LoadError: cannot load such file -- net/ssh
I did what it suggested and ran bundle exec rake -P. Here was the output from that:
rake aborted!
LoadError: cannot load such file -- net/ssh
This is the tough part when working through a tutorial book. I do not think I missed any steps. I'm not sure what to do here. Any tips would be greatly appreciated.
I figured it out and hope this helps anyone else having the same issue.
What eventually did it for me was that I had to update the fog gem. The book has you use version 1.29.0. For whatever reason: that version was not working for me.
In my Gemfile I simply put gem "fog", deleted my Gemfile.lock and ran bundle so that it would go out and grab the latest version.
Afterwards I looked inside the Gemfile.lock and noticed it grabbed the fog version of 1.38.0. Now when I ran git push heroku master it worked.
What led me to try out updating fog was this issue on the fog github page.
In case anyone was curious: I was using rails 4.2.1, as well as ruby 2.2.1 as the book tells you to.
Did some research but can't figure out what caused the rejection when I tried to git push heroku master.
Here is my the git repo: https://github.com/leonahu/IMGfeed
and this is the details of the rejection:
remote: Tasks: TOP => environment
remote: (See full trace by running task with --trace)
remote: !
remote: ! Precompiling assets failed.
remote: !
remote: ! Push rejected, failed to compile Ruby app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to feedimg.
remote:
The error says that the assets failed to precompile, so you should precompile them by running bundle exec rake assets:precompile
Or specifically for production run RAILS_ENV=production bundle exec rake assets:precompile
Make sure that you have this line of code in your config/application.rb file: config.assets.initialize_on_precompile = false
After this, try to push to heroku again
I think you might forget to set config.secret_key_base in production. Run:
heroku config:set SECRET_KEY_BASE=your_secret_key_base
To get a new secret key you can run bundle exec rake secret in the project's root folder.
I tried all the suggestions above but it did not work on my app ( Thanks everyone who tried to help nevertheless.)
What ended up working for me is I basically forced the Heroku by running:
git push heroku master --force
After that, I was able to git push heroku master again.