I have an image asset in app/assets/images which I am trying to compile before deploying in production as per asset pipeline guide.
Upon trying to execute:
RAILS_ENV=production rails assets:precompile
I get the following error:
rails aborted!
Errno::ENOENT: No such file or directory - C:/../bin/yarn --version
Tasks: TOP => assets:precompile => yarn:install
(See full trace by running task with --trace)
The above error also happens when I run
rails yarn:install
Checking yarn version
$ yarn
yarn install v1.22.5
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.80s.
I have installed webpacker 5.2. I tried to check the bin/yarn file but did not find any problem. Any ideas?
I have similar problem, and this deals because using rails 6.1 that has this issue, they have pushed merge to branch, but if you still has problem
temporary solution that I did
create one file /bin/yarn
if you using linux just put content as below
#!/bin/bash
exit 0
and make sure it executable, by running chmod 755 /bin/yarn
now you can run precompile command
Related
I have a previously deployed Ruby on Rails API that I wanted to add some additional seed data to.
I am getting the following error when I deploy from either the Heroku CLI or from the web interface:
-----> Ruby app detected
-----> Installing bundler 2.0.2
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.6.5
-----> Installing dependencies using bundler 2.0.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
bash: /tmp/build_9062c7d5995d7f7c573d9509eb8f19d5/bin/bundle: cannot execute binary file: Exec format error
Bundler Output: bash: /tmp/build_9062c7d5995d7f7c573d9509eb8f19d5/bin/bundle: cannot execute binary file: Exec format error
!
! Failed to install gems via Bundler.
!
! Push rejected, failed to compile Ruby app.
! Push failed
I am not sure what the issue is. I have tried:
Deploying to a brand new Heroku application
Adding a Procfile
Adding a Ruby build pack
Resolving some outstanding security warnings from Github by running Bundle update locally and getting the new gemfile into my repo, prior to this there were no new Gem changes
None of these has changed the error I am getting.
If I clone the repo from github into a new folder on my Macbook I am able to get it up and running locally.
I have the following on my Macbook:
Ruby Version 2.6.5p114
Rails Version 6.0.3.2
Google does not seem to be turning up much, aside from some references to CPU architecture which I assume I have no control of in the Heroku environment.
My feeling is that it is related to bash being unable to execute bin/bundle but I've no idea why or how to resolve.
I vaguely recall having issues previously on this app, in that I was not able to run heroku run rake commands, possibly getting a similar error message, but to resolve I think I was able to simply run heroku run bin/rake
I believe the original rails new command was run on Windows 10 WSL environment in case that is relevant.
EDIT: I'm able to recreate a similar issue with rake, but the fix for rake does not work for bundle and I'm not even sure if it would help with the deployment issue.
➜ appbackend git:(master) heroku run rake
Running rake on ⬢ heroku-name-40049... up, run.8396 (Hobby)
bash: /app/bin/bundle: cannot execute binary file: Exec format error
➜ appbackend git:(master) heroku run bin/rake
Running bin/rake on ⬢ heroku-name-40049... up, run.5201 (Hobby)
Abort testing: Your Rails environment is running in production mode!
➜ appbackend git:(master)
➜ appbackend git:(master) heroku run bundle install
Running bundle install on ⬢ heroku-name-40049... up, run.7746 (Hobby)
bash: /app/bin/bundle: cannot execute binary file: Exec format error
➜ appbackend git:(master) heroku run bin/bundle install
Running bin/bundle install on ⬢ heroku-name-40049... up, run.4632 (Hobby)
bash: bin/bundle: cannot execute binary file: Exec format error
Turns out it was exactly as the error message stated Exec format error.
The bundle file in the bin directory was not the right format. Not sure how I managed to deploy in the first place (the history of this file has only 2 version in the repo, the first commit, and now the fix).
I was able to resolve by overwriting the bundle file from a different working rails install. Appreciated the help provided.
After following each step in the webpacker upgrading section, an upgrade from 4.2.2 to 5.0.1, is causing yarn install to no longer be invoked during rails assets:precompile. This is causing front-end packages sourced from our package.json file to not be found during the asset compilation process.
This is highlighted when CI runs rails assets:precompile. Previously assets:precompile would run yarn install before compiling our application.js file. I've added the --trace flag and it runs as if it skips yarn install.
** Invoke yarn:install (first_time)
** Execute yarn:install
** Execute assets:precompile
rails aborted!
Sprockets::FileNotFound: couldn't find file 'moment' with type 'application/javascript'
The same CI run with the older webpack version displays the yarn install output as expected. Has anyone run into this same issue when bumping to 5.x?
We are currently on Rails 5.2.4 which didn't have the yarn binstub. Webpacker 5.0.1's yarn install task calls the binstub which internally invokes yarnpkg. Without the presence of the binstub, the rake task would do nothing which is what we were experiencing. Adding the missing binstub solved our issues.
/bin/yarn
#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
begin
exec "yarnpkg", *ARGV
rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
end
Comment/remote the sprockets line from config/application.rb:
# config/application.rb
# Remove the line below
require "sprockets/railtie"
You can also remove config.assets ... lines from all your config/environment/*.rb files:
# config/environment/*.rb
# Remove the following lines
config.assets.debug = true
config.assets.quiet = true
These are no longer required with Webpacker and could also cause errors.
Hope that helps :)
I am in the process of deploying my Rails application with Passenger and when I run this command to get my application ready and set for production I get this yarn message but no further actions are run.
bundle exec rake assets:precompile db:migrate RAILS_ENV=production
Output from that command:
yarn install v1.3.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
info Lockfile not saved, no dependencies.
Done in 0.04s.
When this is finished running I hop into the Rails console and run Rails.env and the result is development. I have removed and re-installed Yarn but that is no luck. There are no Yarn dependencies so I am confused as to why I need it in the first place. If I run the bundle exec command without Yarn installed I get this message:
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
Does anybody know how to by-pass this or set this to production mode without having Yarn installed?
I have also tried running:
RAILS_ENV=production rake assets:precompile
But get this rather large input:
/var/www/isharelessons/code/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/file_utils.rb:10: warning: already initialized constant FileUtils::RUBY
/var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/file_utils.rb:10: warning: previous definition of RUBY was here
/var/www/isharelessons/code/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/file_utils.rb:109: warning: already initialized constant FileUtils::LN_SUPPORTED
/var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/file_utils.rb:109: warning: previous definition of LN_SUPPORTED was here
/var/www/isharelessons/code/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/file_utils_ext.rb:17: warning: already initialized constant Rake::FileUtilsExt::DEFAULT
/var/lib/gems/2.3.0/gems/rake-12.3.0/lib/rake/file_utils_ext.rb:17: warning: previous definition of DEFAULT was here
WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
[....]
When you run a command like
bundle exec rake assets:precompile db:migrate RAILS_ENV=production
It will use the production environment when executing those commands, but it doesn't put you in the environment beyond the duration of that single rake command. If you then run
$ rails c
2.4.2 :001 > Rails.env
=> "development"
It's showing development, because RAILS_ENV is empty, and when empty, the default environment is development.
When you specify an environment on the command line at the end of a rake command, it doesn't change the shell's environment; it's just an argument to the rake command, and does not persist in any way.
Similarly, when you prefix a command with the environment, like
RAILS_ENV=production rake assets:precompile
It does not persist beyond that single command. It's a temporary variable assignment. That does change the shell variable, but only for the duration of that command line, and it also does not change the environment for future commands.
If you want to set the environment for your shell session, so that it affects all future commands (until you log out or start a new shell), then you have to export the variable:
$ export RAILS_ENV=production
$ rails c
2.4.2 :001 > Rails.env
=> "production"
Rails C and Rails S not working when in the correct directory.
have tried:
$ bundle exec rake rails:update:bin
this returns the following error:
bundler: command not found: rails:update:bin
Install missing gem executables with `bundle install`
I have ran:
Bundle Install
this still returns the same error
Have changed directories (higher and lower), repeated steps and attempted commends for same result.
I was running rails server, when i stopped the server and tried to restart server, the error appeared, so I'm thinking this has something to do with a physical location change (potentially the bin file), which is consistent as when I try and run a bin/rails command, i'm receiving an error of:
bundler: command not found: rails:update:bin
Install missing gem executables with `bundle install`
I have tried to rake the bin folder as below:
rake rails:update:bin
however I am receiving this error:
rake aborted!
Don't know how to build task 'rails:update:bin' (see --tasks)
Finally, I have checked the physical location and there is a .bin file, however this folder is empty and it's not in a .gitignore directory.
Ancillary information
Rails version: 5.1.4
ruby version: 2.3.4
Server: heroku
OS. Ubuntu 16.04 (via virtualbox).
I have not upgraded rails, this is a fresh install
I am at a loss.
rails update:bin or rake update:bin These are the right ways that execute a rake task.
In the rails guides they have an example on how to precompile assets with Capistrano. It is as simple as adding load 'deploy/assets' to the Capfile. I simply want to achieve the same effect, precompiling assets, while using Travis CI instead. This is what I've done so far:
script/travis.sh:
run "bundle exec rake assets:precompile"
.travis.yml:
before_install:
- chmod +x script/travis.sh
script: script/travis.sh
language: ruby
rvm:
- 2.2
deploy:
provider: heroku
When this is built on Travis it fails and I get this from the log:
$ script/travis.sh
script/travis.sh: line 1: run: command not found
The command "script/travis.sh" exited with 127.
I also want to add that my shell script knowledge is very limited.
I'm not entirely sure, but I'm leaning towards the run command not being available in the travis shell, as against Capistrano. I'd say you should probably just leave your travis.sh as:
bundle exec rake assets:precompile
And try again. Let me know the results of that