Getting an error from "lib/generators/templates/_install_node.erb"
shinyamagami opened this issue · 6 comments
(erb):23:in `get_binding': undefined method `split' for nil:NilClass (NoMethodError)
from /Users/shin/.rbenv/versions/3.1.3/lib/ruby/3.1.0/erb.rb:905:in `eval'
from /Users/shin/.rbenv/versions/3.1.3/lib/ruby/3.1.0/erb.rb:905:in `result'
from /Users/shin/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dockerfile-rails-1.0.7/lib/generators/dockerfile_generator.rb:142:in `render'
from /Users/shin/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dockerfile-rails-1.0.7/lib/generators/templates/Dockerfile.erb:57:in `template'
I was trying to deploy my app to Fly.io and saw this error. How should I solve this error?
Solved by adding .node-version.
Facing the same. Adding .node-version
did not help
Yeah, I have been facing the same issue after I had thought I solved the issue.
Just faced this issue and looked into it. This issue occurs when the Gemfile or any dependencies use execjs
.
I resolved it by removing a dependency that required execjs from the project. I was fortunate enough to be able to do this. But I am guessing others might not be able to.
This line here is what is causing the issue -
Looking at the complex conditions in the Dockerfile erb template for Node.js & Yarn, IMHO these can be straight-forward options rather than auto-detecting pieces of tech/tools being used for Node.js.
Temporary solution
For those that face this issue, since this rubygem includes a command that only needs to be run once, you could do this:
# Use code or your favourite editor to open the Dockerfile.erb template
code $(bundle show dockerfile-rails)/lib/generators/templates/Dockerfile.erb
Then replace this part in line-65 (below)
<%= render partial: 'install_node', locals: {node_version: using_execjs? ? nil : node_version, yarn_version: File.exist?('yarn.lock') ? yarn_version : nil} %>
with the following:
<%= render partial: 'install_node', locals: {node_version: node_version, yarn_version: File.exist?('yarn.lock') ? yarn_version : nil} %>
This issue occurs when the Gemfile or any dependencies use execjs.
Why do these test cases pass then?
- https://github.com/fly-apps/dockerfile-rails/blob/main/test/test_execjs_node.rb
- https://github.com/fly-apps/dockerfile-rails/blob/main/test/test_execjs_importmap.rb
Reproduction instructions would be helpful here.
IMHO these can be straight-forward options rather than auto-detecting pieces of tech/tools being used for Node.js
The intent is to "just work" whenever possible. Options are for cases that can't be detected
this rubygem includes a command that only needs to be run once
The intent is to have a command that can be re-run as your application changes.
I attempted to reproduce the issue with a fresh Rails 7 app by adding react-rails and dockerfile-rails to it. Could not reproduce - generating a dockerfile works as expected. I just saw your recent commit that the issue is due to the Yarn version. Thank you for looking into it and fixing it.