Discourse Development: Failed to register/update a ServiceWorker

The following appears periodically (every few seconds) in the JavaScript console.

Failed to register/update a ServiceWorker for scope ‘http://localhost:3000/’: Load failed with status 500 for script ‘http://localhost:3000/service-worker.js’.

The terminal output looks like this:

D, [2018-06-03T20:28:07.080027 #19420] DEBUG -- : Delivering messages [] to client 6eeef67735ba4dab8c7226fa01287a24 for user 1 (chunked)
D, [2018-06-03T20:28:08.098346 #19420] DEBUG -- :   UserAuthToken Load (0.8ms)  SELECT  "user_auth_tokens".* FROM "user_auth_tokens" WHERE ((auth_token = 'OmH38KrXB6FtPKlFofE3BgvZevI=' OR
                          prev_auth_token = 'OmH38KrXB6FtPKlFofE3BgvZevI=') AND rotated_at > '2018-04-04 18:28:08.095703') LIMIT 1
D, [2018-06-03T20:28:08.103359 #19420] DEBUG -- :   User Load (0.9ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
D, [2018-06-03T20:28:08.107814 #19420] DEBUG -- :    (0.5ms)  SELECT "groups"."id" FROM "groups"
D, [2018-06-03T20:28:08.112021 #19420] DEBUG -- : Delivering messages [] to client 6eeef67735ba4dab8c7226fa01287a24 for user 1 (chunked)
I, [2018-06-03T20:28:09.096577 #19420]  INFO -- : Started GET "/service-worker.js" for 127.0.0.1 at 2018-06-03 20:28:09 +0200
I, [2018-06-03T20:28:09.144970 #19420]  INFO -- : Processing by StaticController#service_worker_asset as JS
D, [2018-06-03T20:28:09.148873 #19420] DEBUG -- :   UserAuthToken Load (1.0ms)  SELECT  "user_auth_tokens".* FROM "user_auth_tokens" WHERE ((auth_token = 'OmH38KrXB6FtPKlFofE3BgvZevI=' OR
                          prev_auth_token = 'OmH38KrXB6FtPKlFofE3BgvZevI=') AND rotated_at > '2018-04-04 18:28:09.146556') LIMIT 1
D, [2018-06-03T20:28:09.152199 #19420] DEBUG -- :   User Load (1.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
I, [2018-06-03T20:28:09.156395 #19420]  INFO -- : Completed 500 Internal Server Error in 10ms (ActiveRecord: 2.1ms)


F, [2018-06-03T20:28:09.163221 #19420] FATAL -- : 
Errno::ENOENT - No such file or directory @ rb_file_s_ctime - /home/phil/dev/repos/discourse/public/assets:
  app/controllers/static_controller.rb:167:in `block (2 levels) in service_worker_asset'
  actionpack (5.1.4) lib/action_controller/metal/mime_responds.rb:201:in `respond_to'
  app/controllers/static_controller.rb:159:in `service_worker_asset'
  actionpack (5.1.4) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
  actionpack (5.1.4) lib/abstract_controller/base.rb:186:in `process_action'
  actionpack (5.1.4) lib/action_controller/metal/rendering.rb:30:in `process_action'
  actionpack (5.1.4) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (5.1.4) lib/active_support/callbacks.rb:131:in `run_callbacks'
  actionpack (5.1.4) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (5.1.4) lib/action_controller/metal/rescue.rb:20:in `process_action'
  actionpack (5.1.4) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (5.1.4) lib/active_support/notifications.rb:166:in `block in instrument'
  activesupport (5.1.4) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  activesupport (5.1.4) lib/active_support/notifications.rb:166:in `instrument'
  actionpack (5.1.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (5.1.4) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
  activerecord (5.1.4) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
  actionpack (5.1.4) lib/abstract_controller/base.rb:124:in `process'
  actionview (5.1.4) lib/action_view/rendering.rb:30:in `process'
  rack-mini-profiler (1.0.0) lib/mini_profiler/profiling_methods.rb:104:in `block in profile_method'
  actionpack (5.1.4) lib/action_controller/metal.rb:189:in `dispatch'
  actionpack (5.1.4) lib/action_controller/metal.rb:253:in `dispatch'
  actionpack (5.1.4) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
  actionpack (5.1.4) lib/action_dispatch/routing/route_set.rb:31:in `serve'
  actionpack (5.1.4) lib/action_dispatch/journey/router.rb:50:in `block in serve'
  actionpack (5.1.4) lib/action_dispatch/journey/router.rb:33:in `serve'
  actionpack (5.1.4) lib/action_dispatch/routing/route_set.rb:834:in `call'
  rack-protection (2.0.1) lib/rack/protection/frame_options.rb:31:in `call'
  lib/middleware/omniauth_bypass_middleware.rb:24:in `call'
  rack (2.0.5) lib/rack/conditional_get.rb:25:in `call'
  rack (2.0.5) lib/rack/head.rb:12:in `call'
  rack (2.0.5) lib/rack/session/abstract/id.rb:232:in `context'
  rack (2.0.5) lib/rack/session/abstract/id.rb:226:in `call'
  actionpack (5.1.4) lib/action_dispatch/middleware/cookies.rb:613:in `call'
  activerecord (5.1.4) lib/active_record/migration.rb:556:in `call'
  actionpack (5.1.4) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
  activesupport (5.1.4) lib/active_support/callbacks.rb:97:in `run_callbacks'
  actionpack (5.1.4) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
  actionpack (5.1.4) lib/action_dispatch/middleware/executor.rb:12:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  actionpack (5.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
  actionpack (5.1.4) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
  logster (1.2.9) lib/logster/middleware/reporter.rb:31:in `call'
  railties (5.1.4) lib/rails/rack/logger.rb:36:in `call_app'
  railties (5.1.4) lib/rails/rack/logger.rb:26:in `call'
  config/initializers/100-quiet_logger.rb:16:in `call'
  config/initializers/100-silence_logger.rb:29:in `call'
  actionpack (5.1.4) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
  actionpack (5.1.4) lib/action_dispatch/middleware/request_id.rb:25:in `call'
  rack (2.0.5) lib/rack/method_override.rb:22:in `call'
  actionpack (5.1.4) lib/action_dispatch/middleware/executor.rb:12:in `call'
  actionpack (5.1.4) lib/action_dispatch/middleware/static.rb:125:in `call'
  rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
  lib/middleware/missing_avatars.rb:21:in `call'
  lib/middleware/turbo_dev.rb:34:in `call'
  rack-mini-profiler (1.0.0) lib/mini_profiler/profiler.rb:285:in `call'
  message_bus (2.1.5) lib/message_bus/rack/middleware.rb:63:in `call'
  railties (5.1.4) lib/rails/engine.rb:522:in `call'
  railties (5.1.4) lib/rails/railtie.rb:185:in `method_missing'
  rack (2.0.5) lib/rack/urlmap.rb:68:in `block in call'
  rack (2.0.5) lib/rack/urlmap.rb:53:in `call'
  puma (3.9.1) lib/puma/configuration.rb:224:in `call'
  puma (3.9.1) lib/puma/server.rb:602:in `handle_request'
  puma (3.9.1) lib/puma/server.rb:435:in `process_client'
  puma (3.9.1) lib/puma/server.rb:299:in `block in run'
  puma (3.9.1) lib/puma/thread_pool.rb:120:in `block in spawn_thread'

This makes it quite annoying finding the correct logger statements. How do I get rid of it?

Looks like you have force_https enabled. Try running bin/rails c it will give you a hint at what to do to fix it :innocent:

3 إعجابات

Going to the settings shows “force https” as being disabled. I haven’t changed any discourse setting or configuration after cloning the repository and running it. I’ve just worked on a plugin. No other files were changed.

Running the command bin/rails c doesn’t provide any hint that seems to be relevant, either. Maybe it’s something else?

phil@RAUMSTATION in ~/dev/repos/discourse on master
👻 bin/rails c             
/home/phil/.rvm/gems/ruby-2.4.1/gems/i18n-0.8.6/lib/i18n.rb:12: warning: already initialized constant I18n::RESERVED_KEYS
/home/phil/.rvm/gems/ruby-2.4.1/gems/i18n-0.8.6/lib/i18n.rb:12: warning: previous definition of RESERVED_KEYS was here
/home/phil/.rvm/gems/ruby-2.4.1/gems/i18n-0.8.6/lib/i18n.rb:13: warning: already initialized constant I18n::RESERVED_KEYS_PATTERN
/home/phil/.rvm/gems/ruby-2.4.1/gems/i18n-0.8.6/lib/i18n.rb:13: warning: previous definition of RESERVED_KEYS_PATTERN was here
Loading development environment (Rails 5.1.4)
[1] pry(main)> 

Did you compile assets in your dev environment at some point? You may still have an assets manifest file that can cause this. Try clearing your public/assets folder.

No such directory exists. Investigating this more closely, it turns out that this is precisely the problem.

mkdir public/assets

Creating the directory solves the issue. There probably should be a check against this somewhere, right?

إعجابَين (2)

Oh weird. Looks pretty minor since it’s only affecting dev envs, but we’ll get this fixed.

إعجابَين (2)

Fixed, development service workers should act better without that directory - thanks for reporting this! :pineapple:

https://github.com/discourse/discourse/commit/44ee26721a4671d318b4d69c8d63855a089ce347

5 إعجابات