Skip to content

Commit ce7cdd7

Browse files
committed
webpacker:install does not require webpacker.yml
If you run ./bin/rails webpacker:install on a rails app with no config/webpacker.yml, we get a crash with this error: > Webpacker configuration file not found webpacker-v6/config/webpacker.yml. > Please run rails webpacker:install Error: No such file or directory @ rb_check_realpath_internal - webpacker-v6/config/webpacker.yml With this fix, allow installer to run. Problem solved with a global to indicate installing so that default configuration is used rather than crashing because the yet to be installed config/webpacker.yml is not yet installed.
1 parent 9d55518 commit ce7cdd7

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/tasks/webpacker/install.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
44
namespace :webpacker do
55
desc "Install Webpacker in this application"
66
task install: [:check_node, :check_yarn] do |task|
7+
@@webpacker_installing = true
78
prefix = task.name.split(/#|webpacker:install/).first
89

910
if Rails::VERSION::MAJOR >= 5

lib/webpacker/configuration.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ def load
8080
end
8181
config[env].deep_symbolize_keys
8282
rescue Errno::ENOENT => e
83-
raise "Webpacker configuration file not found #{config_path}. " \
84-
"Please run rails webpacker:install " \
85-
"Error: #{e.message}"
86-
83+
if @@webpacker_installing
84+
{}
85+
else
86+
raise "Webpacker configuration file not found #{config_path}. " \
87+
"Please run rails webpacker:install " \
88+
"Error: #{e.message}"
89+
end
8790
rescue Psych::SyntaxError => e
8891
raise "YAML syntax error occurred while parsing #{config_path}. " \
8992
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \

0 commit comments

Comments
 (0)