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

rake webpacker:check_node errors out if no node installed #954

Closed
tdegrunt opened this issue Oct 16, 2017 · 4 comments · Fixed by #1105
Closed

rake webpacker:check_node errors out if no node installed #954

tdegrunt opened this issue Oct 16, 2017 · 4 comments · Fixed by #1105

Comments

@tdegrunt
Copy link

tdegrunt commented Oct 16, 2017

Version: webpacker 3.0.2
Ruby: 2.4.2

rake webpacker:check_node --trace                                                                                                     ⏎
** Invoke webpacker:check_node (first_time)
** Execute webpacker:check_node
/Users/tdegrunt/.rbenv/versions/2.4.2/bin/rake: No such file or directory - node
rake aborted!
NoMethodError: undefined method `strip' for nil:NilClass
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/webpacker-3.0.2/lib/tasks/webpacker/check_node.rake:16:in `block (2 levels) in <top (required)>'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/task.rb:251:in `block in execute'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/task.rb:251:in `each'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/task.rb:251:in `execute'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/task.rb:195:in `block in invoke_with_call_chain'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/task.rb:188:in `invoke_with_call_chain'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/task.rb:181:in `invoke'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/application.rb:153:in `invoke_task'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/application.rb:109:in `block (2 levels) in top_level'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/application.rb:109:in `each'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/application.rb:109:in `block in top_level'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/application.rb:118:in `run_with_threads'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/application.rb:103:in `top_level'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/application.rb:81:in `block in run'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/application.rb:179:in `standard_exception_handling'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/lib/rake/application.rb:78:in `run'
/Users/tdegrunt/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rake-12.1.0/exe/rake:27:in `<top (required)>'
/Users/tdegrunt/.rbenv/versions/2.4.2/bin/rake:23:in `load'
/Users/tdegrunt/.rbenv/versions/2.4.2/bin/rake:23:in `<main>'
Tasks: TOP => webpacker:check_node

If this code in check_node.rake is changed:

      begin
        node_version = `node -v`
      rescue Errno::ENOENT
        node_version = `nodejs -v`
        raise Errno::ENOENT if node_version.blank?
      end

to:

      begin
        node_version = `node -v`
      rescue Errno::ENOENT
        node_version = `nodejs -v`
      end
      raise Errno::ENOENT if node_version.blank?

it seems to behave and report:

rake webpacker:check_node --trace                                                                                                     ⏎
** Invoke webpacker:check_node (first_time)
** Execute webpacker:check_node
/Users/tdegrunt/.rbenv/versions/2.4.2/bin/rake: No such file or directory - node
Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/

I thought one could re-raise in rescue blocks?

@SergiiVdovareize
Copy link

SergiiVdovareize commented Nov 22, 2017

I have a related question. Why doesn't the check_node task see node? node is installed using nvm. node -v returns the version. But the task says No such file or directory - node. At the same moment, the check_yarn task sees the yarn version correctly.
It happens only during the deployment using capistrano. If I copy the check_node task to the project and run it, node version is returned correctly

UPD: this helped - koenpunt/capistrano-nvm#25 (comment)

@mxmzb
Copy link

mxmzb commented Nov 23, 2017

I have the same issue when I try to deploy my app with Docker. It fails the deployment with the output above at the precompiling process...

@gauravtiwari
Copy link
Member

      begin
        node_version = `node -v`
      rescue Errno::ENOENT
        node_version = `nodejs -v`
        raise Errno::ENOENT if node_version.blank?
      end

This seems to work fine and report as expected. Where is this happening? locally or during deployment.

@brasic
Copy link
Contributor

brasic commented Dec 14, 2017

I can also confirm this is happening when node is not installed. The reason is that when activesupport is loaded this monkeypatch suppresses Errno::ENOENT. Simple reproduction script:

require 'active_support/core_ext/kernel/agnostics'

begin
  node_version = `node -v`
rescue Errno::ENOENT
  node_version = `nodejs -v`
  raise Errno::ENOENT if node_version.blank?
end

puts "node_version is '#{node_version}'" # without AS monkeypatch, we would never reach this line

The fallback for legacy versions of node introduced in #798 doesn't actually work because of this. Since webpacker is always used alongside rails, this task should not assume that backticks behave as they do in vanilla ruby.

Edit: I've opened #1105 to restore the "expected" behavior.

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

Successfully merging a pull request may close this issue.

5 participants