Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No such file or directory - /usr/src/app/bin/yarn #40795

Closed
stefanahman opened this issue Dec 10, 2020 · 21 comments
Closed

No such file or directory - /usr/src/app/bin/yarn #40795

stefanahman opened this issue Dec 10, 2020 · 21 comments

Comments

@stefanahman
Copy link

Steps to reproduce

When I run bin/rails assets:precompile I get a Errno::ENOENT exception. Probably related to #40739.

Expected behavior

I expect the precompilation of assets to fallback to existing yarn when not found in bin directory.

Actual behavior

RUN RAILS_ENV=production bin/rails assets:precompile
rails aborted!
Errno::ENOENT: No such file or directory - /usr/src/app/bin/yarn
 
Tasks: TOP => assets:precompile => yarn:install

System configuration

Rails version: 6.1.0

Ruby version: 2.7.2

tskogberg pushed a commit to barsoom/pipeline that referenced this issue Dec 11, 2020
When running `rake assets:precompile`, `railties-6.1.0/lib/rails/tasks/yarn.rake` gets called
and since we don't have yarn installed it will cause an exception.

There is an issue on this: rails/rails#40795.

When fixed, this temporary fix should be removed.
@doits
Copy link
Contributor

doits commented Dec 11, 2020

Looks like bin/yarn is not present in your project, but it should be if you want to use javascript.

Try to run bundle exec rails app:update:bin. Does this create bin/yarn and fix the issue? (rails app:update should have done this already starting from 5.1 or 5.2 I think).

doits added a commit to Stellenticket/rails that referenced this issue Dec 11, 2020
One reason why it could be missing because Rails was upgraded but `rails
app:update` was not run.

Running `rails app:update:bin` should create it.

refs rails#40795
@mvz
Copy link

mvz commented Dec 11, 2020

If you run rails new --skip-javascript to create a Rails application, yarn:install will still be run when running assets:precompile.

@mvz
Copy link

mvz commented Dec 11, 2020

Running bundle exec rails app:update:bin gives:

       exist  bin
   identical  bin/rails
   identical  bin/rake
   identical  bin/setup
      create  bin/spring
      create  bin/yarn
      remove  bin/spring
      remove  bin/yarn

This is in a fresh Rails 6.1 application created with rails new --skip-bundle --skip-test-unit --skip-spring --skip-bootsnap --skip-listen --skip-javascript --skip-webpack-install.

@edariedl
Copy link

edariedl commented Dec 11, 2020

We are still using sprockets to compile javascripts and we are getting the same error. It is was caused by this change #40722 (b087511)

full stack trace:

[project#rails-6-1]→ rails assets:precompile --trace 
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke yarn:install (first_time)
** Execute yarn:install
rails aborted!
Errno::ENOENT: No such file or directory - /project_path/bin/yarn
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.1.0/lib/rails/tasks/yarn.rake:13:in ``'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.1.0/lib/rails/tasks/yarn.rake:13:in `block (2 levels) in <main>'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `block in execute'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `each'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `execute'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:243:in `block in invoke_prerequisites'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:241:in `each'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:241:in `invoke_prerequisites'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:188:in `invoke'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:160:in `invoke_task'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `each'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block in top_level'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:125:in `run_with_threads'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:110:in `top_level'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.1.0/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.1.0/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/rake_module.rb:59:in `with_application'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.1.0/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.1.0/lib/rails/command.rb:52:in `invoke'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.1.0/lib/rails/commands.rb:18:in `<main>'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `block in require'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:299:in `load_dependency'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require'
/project_path/bin/rails:8:in `<top (required)>'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `load'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `call'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/spring-2.1.1/lib/spring/client/command.rb:7:in `call'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/spring-2.1.1/lib/spring/client.rb:30:in `run'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/spring-2.1.1/bin/spring:49:in `<top (required)>'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `load'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<top (required)>'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/edariedl/.rbenv/versions/2.6.6/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/project_path/bin/spring:16:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => assets:precompile => yarn:install

system call swallows the problem and returns nil if command doesn't exist. Backgticks `` on the other hand raises an exception. That is the reason it is raising exceptions.

It worked fine in 6.1.0.rc2, it was broken by final release.

@edariedl
Copy link

running bundle exec rails app:update:bin --trace gives me pretty much the same output as @mvz above:

** Invoke app:update:bin (first_time)
** Execute app:update:bin
       exist  bin
   identical  bin/rails
   identical  bin/rake
   identical  bin/setup
   identical  bin/spring
      create  bin/yarn
      remove  bin/yarn

@doits
Copy link
Contributor

doits commented Dec 11, 2020

Allright, thanks for trying it out. It looks like the problem in the end lies in those lines then:

# Run Yarn prior to Sprockets assets precompilation, so dependencies are available for use.
if Rake::Task.task_defined?("assets:precompile")
Rake::Task["assets:precompile"].enhance [ "yarn:install" ]
end

It always runs the task on precompiling assets, even though it seems it shouldn't because you skipped javascript. That is why it removes bin/yarn on your setup on rails app:update:bin. But it still tries to call it by running yarn:install.

Before b087511, the task would fail silently. It still was a bug that it was run at all but it did no harm. Now it breaks the pipeline.

I already have PR #40785 ready and will change it so that if the task fails it will at least continue with everything else like before. Edit: I just changed it so it only runs yarn:install automatically if bin/yarn is present, which should be the proper fix.

To fix it properly something must be done with the lines I quoted above – maybe they should even be removed completely so yarn:install is never run automatically (just like bundle install has to be done manually, too). At least it should only be run when it should, e.g. when javascript is enabled in this project. Anyways, this is something for the Rails team to decide.

doits added a commit to Stellenticket/rails that referenced this issue Dec 11, 2020
Based on discussion in rails#40795, it
looks like `yarn:install` is *always* run, even if the Rails project
disabled javascript and there is no `bin/yarn`.

Check for the existence of `bin/yarn` to decide if `yarn:install` should
be run or not.

The check for this is taken from `railties/lib/rails/app_updater.rb`,
where it does the same:

```ruby
         options[:skip_javascript] = !File.exist?(Rails.root.join("bin", "yarn"))
```
@doits
Copy link
Contributor

doits commented Dec 11, 2020

I updated #40785 to only run yarn:install on assets:precompile if bin/yarn is present (which seems to be the way to check if the project was created with --skip-javascript or not).

Can you please try it out @mvz, @edariedl and report back if this fixes it for you?

@edariedl
Copy link

@doits Looks like it fixes it for us 👍, thanks, hopefully it gets merged soon.

@mvz
Copy link

mvz commented Dec 11, 2020

@doits I can confirm that this fixes things for my case as well. Thanks!

@mukinabis
Copy link

What temporary solution is suitable? I really need version 6.1, but because of this problem, I can't update.

@doits
Copy link
Contributor

doits commented Dec 14, 2020

@mukinabis see barsoom/pipeline@3906724 where the rake task is overwritten to do nothing

@KevinBongart
Copy link

@rafaelfranca Do you have a minute to explain the rationale behind closing this issue? As far as I understand, yarn is now a required dependency for Rails 6.1.0 apps so that rails assets:precompile work, even if there is nothing for yarn to install. Before Rails 6.1.0, rails assets:precompile worked fine without yarn installed on a system as rake yarn:install failed silently.

@edariedl
Copy link

@KevinBongart fix was merged #40785, no need for open issue anymore.

@samstickland
Copy link

Any idea what is happening here.. this is a project I have upgraded to Rails 6.1, but when I run rails app:update:bin``yarn is being installed and then removed:

 bundle exec rails app:update:bin
       exist  bin
   identical  bin/rails
   identical  bin/rake
   identical  bin/setup
      create  bin/spring
      create  bin/yarn
      remove  bin/spring
      remove  bin/yarn

The project is using webpacker.

@samstickland
Copy link

Ah, ignore my question.. It is a duplicate of: #40868

damianlegawiec added a commit to spark-solutions/spree that referenced this issue Dec 28, 2020
damianlegawiec added a commit to spark-solutions/spree that referenced this issue Dec 29, 2020
damianlegawiec added a commit to spark-solutions/spree that referenced this issue Dec 29, 2020
damianlegawiec added a commit to spark-solutions/spree that referenced this issue Dec 29, 2020
damianlegawiec added a commit to spark-solutions/spree that referenced this issue Dec 29, 2020
damianlegawiec added a commit to spark-solutions/spree that referenced this issue Dec 29, 2020
@AnthonyFrancis
Copy link

AnthonyFrancis commented Jan 5, 2021

Hey! Has this fix been pushed to the main branch yet? Just installed rails 6.1.0 and still having the same issue.

@espen
Copy link

espen commented Jan 6, 2021

@AnthonyFrancis no new version is released but it is included in 6-1-stable

@dhh
Copy link
Member

dhh commented Jan 7, 2021

As a temporary fix, you can add the following to your Rakefile:

Rake::Task["yarn:install"].clear

namespace :yarn do
  task :install do
    # Do nothing, since there's no yarn
  end
end

@KevinBongart
Copy link

@AnthonyFrancis looks like Rails 6.1.1 was just released and it includes the fix for yarn:install

@maxence33

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests