1

Hypertext /install guide shows you how to add Hypertext to an existing Rails app. I've got to the point where I should be able to launch the legacy app as before, but the routes to image resources can't be resolved. I think I'm just not getting the routes set correctly, on the other hand I haven't changed anything from what the Guide says. This is a first pass at Hyperstack and it feels like something pretty obvious, but it isn't yielding to the simple tests I've tried so far.

routes.rb

    Rails.application.routes.draw do

    mount Hyperstack::Engine => '/hyperstack'  # this route should be first in the routes file so it always matches

/hyperstack/hyper_component.rb

# app/hyperstack/hyper_component.rb
class HyperComponent
  # All component classes must include Hyperstack::Component
  include Hyperstack::Component
  # The Observable module adds state handling
  include Hyperstack::State::Observable
  # The following turns on the new style param accessor
  # i.e. param :foo is accessed by the foo method
  param_accessor_style :accessors
end

/components/shipment.rb

class Shipment < HyperComponent

  # param :my_param
  # param param_with_default: "default value"
  # param :param_with_default2, default: "default value" # alternative syntax
  # param :param_with_type, type: Hash
  # param :array_of_hashes, type: [Hash]
  # other :attributes  # collects all other params into a hash
  # fires :callback  # creates a callback param

  # access params using the param name
  # fire a callback using the callback name followed by a !

  # state is kept and read as normal instance variables
  # but when changing state prefix the statement with `mutate`
  # i.e. mutate @my_state = 12
  #      mutate @my_other_state[:bar] = 17

  # the following are the most common lifecycle call backs,
  # delete any that you are not using.
  # call backs may also reference an instance method i.e. before_mount :my_method

  before_mount do
    # any initialization particularly of state variables goes here.
    # this will execute on server (prerendering) and client.
  end

  after_mount do
    # any client only post rendering initialization goes here.
    # i.e. start timers, HTTP requests, and low level jquery operations etc.
  end

  before_update do
    # called whenever a component will be re-rerendered
  end

  before_unmount do
    # cleanup any thing before component is destroyed
    # note timers are broadcast receivers are cleaned up
    # automatically
  end

  render do
    DIV do
      'Shipment'
    end
  end
end

Command line from start

$ bundle exec foreman start
...
ActionView::Template::Error (couldn't find file 'client_and_server-e8a2a4c02f7542e3e05c' with type 'application/javascript'
...

and later on in the command line,

/Users/john/.rvm/gems/ruby-2.6.2/gems/bootstrap-4.3.1/assets/stylesheets
16:45:00 web.1        |   /Users/john/.rvm/gems/ruby-2.6.2/gems/bootstrap-4.3.1/assets/javascripts):
16:45:00 web.1        |     10: 
16:45:00 web.1        |     11:  
16:45:00 web.1        |     12:   // search path default is public/images
16:45:00 web.1        |     13:   = image_tag "Drayage-LongBeach.jpg", :size => "520x360" 
16:45:00 web.1        |     14:   %p
16:45:00 web.1        |     15:   %p
16:45:00 web.1        |     16: 

John Mount
  • 11
  • 3

1 Answers1

0

based on the fact that it can't find your packed manifest file (which was I assume working before) I suspect that you are on webpacker < 4.0.

Webpacker now stores bundles in /javascripts/js rather than just /javscripts/ and hyperstack installer assumes that.

Keep Current Version of Webpack

Go into config/initializers/assets.rb and you will see towards the end a line like this

Rails.application.config.assets.paths << Rails.root.join('public', 'packs', 'js').to_s

just remove , 'js' and it will work with old webpacker.

There is also a similar line in config/environments/test.rb that needs to be modified as well for hyper-spec to work.

Upgrade Webpack (Recommended - your going to have to do it sooner or later)

Or you can upgrade webpacker to ~> 4.0.

You will need answer "Y" to both conflicts, then you must also delete .babelrc file if it exists, and finally run bin/webpack

  1. Update your Gemfile
  2. bundle install
  3. bundle exec rails webpacker:install answer Y to both conflicts
  4. Delete .babelrc if it exists
  5. Run bin/webpack

This should successfully upgrade webpacker to 4.x, and all should now be well.

Mitch VanDuyn
  • 2,838
  • 1
  • 22
  • 29
  • I agree, let's go to webpack 4.x. Ran gem install webpacker -v 4.0.6 and also added a gem for it to Gemfile. Step 3 however is not happy: ` Acantha:roll365 john$ bundle exec rails webpacker:install ... LoadError: incompatible library version - /Users/john/.rvm/gems/ruby-2.6.2/gems/bindex-0.7.0/lib/skiptrace/cruby.bundle` – John Mount Jun 25 '19 at 14:36
  • So, it's working after I did a gem pristine --all; then bundle install. Replaced the ', .js' elements. This brings us to step 5 which I don't understand (it doesn't seem to be a valid command, is there a webpack cli I missed?). However the app comes up, .jpg and all. As Catmandu predicted the routes work but need to be adjusted to go something useful. Thanks. – John Mount Jun 25 '19 at 16:08