「rails c」は動くけど、「rails s」が動かない現象に遭遇したので、メモしておきます。
先に結論。原因は下記でした。本番環境構築時にローカルで試しに叩いた。
% bundle config set --local without 'test development'
下記と違って、設定が残ってしまうので、解除しないといけない。
% bundle install --without test development
現象
% rails s => Booting Puma => Rails 6.1.6 application starting in development => Run `bin/rails server --help` for more startup options Exiting bin/rails:7: warning: already initialized constant APP_PATH /Users/xxxx/workspace/rails-app-origin/bin/rails:7: warning: previous definition of APP_PATH was here The most common rails commands are: generate Generate new code (short-cut alias: "g") console Start the Rails console (short-cut alias: "c") server Start the Rails server (short-cut alias: "s") test Run tests except system tests (short-cut alias: "t") test:system Run system tests dbconsole Start a console for the database specified in config/database.yml (short-cut alias: "db") new Create a new Rails application. "rails new my_app" creates a new application called MyApp in "./my_app" All commands can be run with -h (or --help) for more information. In addition to those commands, there are: about action_mailbox:ingress:exim action_mailbox:ingress:postfix <省略> webpacker:yarn_install yarn:install zeitwerk:check
最初に試したのは(違ったけど)
「warning: previous definition of APP_PATH was here」の対応をしてみた。
検索すると「rails:update:bin」すると治るとの情報があった。
% rails rails:update:bin rails aborted! Don't know how to build task 'rails:update:bin' (See the list of available tasks with `rails --tasks`) Did you mean? app:update:bin /Users/xxxx/workspace/rails-app-origin/bin/rails:9:in `' /Users/xxxx/workspace/rails-app-origin/bin/spring:15:in ` ' (See full trace by running task with --trace)
「app:update:bin」じゃないかと言われる。
% rails app:update:bin exist bin conflict bin/rails Overwrite /Users/xxxx/workspace/rails-app-origin/bin/rails? (enter "h" for help) [Ynaqdhm] force bin/rails conflict bin/rake Overwrite /Users/xxxx/workspace/rails-app-origin/bin/rake? (enter "h" for help) [Ynaqdhm] force bin/rake conflict bin/setup Overwrite /Users/xxxx/workspace/rails-app-origin/bin/setup? (enter "h" for help) [Ynaqdhm] force bin/setup conflict bin/spring Overwrite /Users/xxxx/workspace/rails-app-origin/bin/spring? (enter "h" for help) [Ynaqdhm] force bin/spring conflict bin/yarn Overwrite /Users/xxxx/workspace/rails-app-origin/bin/yarn? (enter "h" for help) [Ynaqdhm] force bin/yarn
% rails s => Booting Puma => Rails 6.1.4.1 application starting in development => Run `bin/rails server --help` for more startup options Exiting /Users/xxxx/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': cannot load such file -- spring/watcher (LoadError)
動かない。
Gemfileを確認
group :development do gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0'
developmentじゃないと使えない。
bundle config
確認
% bundle config Settings are listed in order of priority. The top value will be used. –delete Set for the current user (/Users/xxxx/.bundle/config): "without" without Set for your local app (/Users/xxxx/workspace/rails-app-origin/.bundle/config): [:test, :development]
「–without test development」が設定されている。
解除
% bundle config --delete without
再確認
% bundle config Settings are listed in order of priority. The top value will be used. –delete Set for the current user (/Users/xxxx/.bundle/config): "without"
「–without」が無くなった。
「rails s」も動くようになりました。
最新化
再度「app:update:bin」を実行(変更なし)
% rails app:update:bin exist bin identical bin/rails identical bin/rake identical bin/setup identical bin/spring identical bin/yarn