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.
Related
I've recently upgraded to latest rails. The upgrade was from 6.0.3.4 to 6.1.3.1.
Everything in development and Production/Heroku worked great prior to the upgrade. Now everything works fine in development (local machine), but fails the rails assets:precompile step on Heroku with the following error message:
remote: -----> Installing node-v12.16.2-linux-x64
remote: -----> Installing yarn-v1.22.4
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: rake aborted!
remote: SassC::SyntaxError: Error: File to import not found or unreadable: bootstrap/scss/bootstrap.
remote: on line 21:1 of app/assets/stylesheets/application.scss
remote: >> #import "bootstrap/scss/bootstrap";
My understanding is that the standard functionality is that it will look in local relative files first, then the node_modules folder.
What is my problem here?
probably the file under node_module and it was not able to find it
try specifying #import "node_modules/bootstrap/scss/bootstrap";
I'm not sure if I'm missing something, but I needed to add NodeJS buildpack to Heroku in addition to the ruby buildpack. Now Heroku runs the yarn install before building the rails app, which must create the node_modules folder. Consequently, the step that failed during the rails build can now find the bootstrap folder in the node_modules.
The only thing I can think of that I changed was upgrading from Rails 6.0 to 6.1.
You can probably run test it locally
NODE_ENV=production bundle exec rails assets:precompile
then run
rake assets:precompile
I get the error:
remote: ! Could not detect rake tasks
04:36
remote: ! ensure you can run `$ bundle exec rake -P` against your app
04:36
remote: ! and using the production group of your Gemfile.
04:36
remote: ! /tmp/build_aa020f9e/bin/rake:8:in `require': cannot load such file -- rake (LoadError)
04:36
remote: ! from /tmp/build_aa020f9e/bin/rake:8:in `<main>'
when running a Heroku deployment pipeline from Codeship
/bin/rake looks like this
#!/usr/bin/env ruby
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError => e
raise unless e.message.include?('spring')
end
require_relative '../config/boot'
require 'rake'
Rake.application.run
so line 8 is require 'rake'
I tried adding gem rake explicitly to my gemfile
Then because production group is mentioned I tried
group :production do
gem 'rake'
end
None of this works and so my code push is rejected by Heroku
remote: ! Push rejected, failed to compile Ruby app.
04:36
remote:
04:36
remote: ! Push failed
Any ideas anyone?I see a similar post on StackOverflow rails cannot load such file -- rake (LoadError) but without a solution?
[I've edited this original response to include a solution]
I have this exact issue too, with an open ticket with Heroku. No response yet, sadly but I found an answer elsewhere via a lucky hit in Google.
Context, for future reference and search engines
remote: -----> Detecting rake tasks
remote:
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: ! /tmp/build_b8f358ab/bin/rake:3:in `require': cannot load such file -- rake (LoadError)
remote: ! from /tmp/build_b8f358ab/bin/rake:3:in `<main>'
remote: !
remote: /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/helpers/rake_runner.rb:106:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)
remote: ensure you can run `$ bundle exec rake -P` against your app
remote: and using the production group of your Gemfile.
remote: /tmp/build_b8f358ab/bin/rake:3:in `require': cannot load such file -- rake (LoadError)
remote: from /tmp/build_b8f358ab/bin/rake:3:in `<main>'
As you've doubtless already found, the suggested bundle exec rake -P command above works fine with any Rails.env setting locally. I, too, tried adding rake to Gemfile explicitly but this made no difference, nor did precompiling assets. Other things to note:
All gems build successfully
This deploy would prompt and update from Heroku-18 to the Heroku-20 platform; does yours?
Rails 5 latest patch, but not Rails 6 yet
Ruby 2.7.2
I don't use Spring so my bin/rake is simpler:
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run
...and as with your more complex code, it's definitely the require 'rake' that fails.
Solution
I can't take credit - it's this answer:
https://stackoverflow.com/a/65604896
...that solved it, only you need to change from 2.1.2 to 2.1.4. Copy-pasting the above solution - again this is not my work, the credit belongs to the OP above:
gem uninstall bundler
gem install bundler --version '2.1.4' # If this doesn't work - see below
rm Gemfile.lock
bundle install
git add Gemfile.lock
git commit -m "Downgrade Bundler to match current Heroku version, so that deployments succeed"
git push heroku
This has solved the issue in my case. Seems like an utterly bizarre solution, but there you go.
If you don't seem to be unable to downgrade Bundler
In the comments on this answer, the OP notes:
Because Bundler version 2.2.10 was installed for me as the "default" I hadnt realised Gem bundler-2.1.4 cannot be uninstalled via gem uninstall bundler Using the cleanup_bundler script documented here enabled me to downgrade to v2.1.4 properly. This then did fix the rake problem.
$ gem uninstall bundler
=> Gem bundler-2.2.10 cannot be uninstalled because it is a default gem
StackOverflow prefer answers to be inline rather than linked externally as external links can break, so once again noting that credit goes to the article linked above:
From all the references I can find, the only way to remove it is to delete the bundler-2.1.4.gemspec file from the gem path. The following commands did the trick for me [...] I wrote a script for you:
#!/usr/bin/env ruby
gempaths = `gem env gempath`.split(":")
gempaths.each do |gempath|
# lookup bundler-*.gemspec files and delete them
# this is the only way to completely cleanup default bundler
# Note: the bundler gemspecs' paths are different for CRuby and JRuby
Dir.glob(gempath.strip + "/specifications/**/bundler-*.gemspec").each { |p| File.delete(p) }
end
# Remember to make this file executable
...so hopefully if you save that as a .rb file somewhere convenient, chmod u+x foo.rb and ./foo.rb - that might solve the problem.
I just had this problem and Heroku seems to have added a section to the official documentation that worked for me:
Bundler 2.2.3+
An app’s Gemfile.lock that is generated with Bundler 2.2.3 locally may not work on Heroku unless the Linux platform is explicitly “locked”:
$ bundle lock --add-platform ruby
$ bundle lock --add-platform x86_64-linux
$ bundle install
$ git add . ; git commit -m "Bundler fix"
I changed nothing in the configuration (no new gems or version changes); just one line of code, but I am now unable to push to heroku. Something must have changed at heroku?
It is Rails 3.2.22.5; Ruby 2.3.1. (Yes, I'm in the middle of upgrading to Rails 5, but it's a huge job, and in the meantime I still need to maintain the existing production system.)
RAILS_ENV=production bundle exec rake -P
works fine. I don't think it's really a rake issue. My best guess is something changed at heroku such that some version of something I have is no longer supported, but I have no idea what. And I'm not getting any informative error messages.
At a loss... I've Googled extensively, but most of the posts are 4+ years old. I tried precompiling locally and checking in only the manifest file. I tried upgrading rake (from 13.0.0 to 13.0.1), and have since put everything back since nothing worked.
remote: Bundle complete! 54 Gemfile dependencies, 118 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 (0.51s)
remote: Cleaning up the bundler cache.
remote: -----> Writing config/database.yml to read from DATABASE_URL
remote: -----> Installing node-v12.16.2-linux-x64
remote: -----> Detecting rake tasks
remote:
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: ! bash: /tmp/build_785c3bf77f08cff81f442938e3386876/bin/rake: /app/vendor/ruby-2.3.1/bin/ruby: bad interpreter: No such file or directory
remote: !
remote: /tmp/buildpackvv7B3/lib/language_pack/helpers/rake_runner.rb:106:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)
I asked heroku support, and they found the problem. Nothing to do with rake or my project itself, as expected (since I hadn't changed anything).
It had to do with the buildpacks. I need a PDF-generator, so I had a "multi-buildpack" set up (done years ago), apparently in a way that's no longer supported. I believe the proximate cause was pointing to a "master" buildpack, instead of the stable release. So somebody checked something in at heroku, and it broke my project :) It would probably only affect people who'd done set it up years ago, on the old cedar stack, as I did.
I ran:
heroku buildpacks:remove https://github.com/heroku/heroku-buildpack-multi.git
heroku buildpacks:add heroku/ruby
heroku buildpacks:add https://github.com/dscout/wkhtmltopdf-buildpack.git
and was able to deploy again!
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 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.