Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating a new app using the Quickstart guide does not work #3031

Closed
maxkadel opened this issue Mar 7, 2023 · 6 comments
Closed

Generating a new app using the Quickstart guide does not work #3031

maxkadel opened this issue Mar 7, 2023 · 6 comments

Comments

@maxkadel
Copy link
Contributor

maxkadel commented Mar 7, 2023

When trying to create a new Blacklight app following the instructions in the Quickstart guide, you cannot start the rails application.

To reproduce

➜  projects ruby --version
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
➜  projects rails --version
Rails 7.0.4.2
➜  projects java -version
openjdk version "19.0.2" 2023-01-17
OpenJDK Runtime Environment Homebrew (build 19.0.2)
OpenJDK 64-Bit Server VM Homebrew (build 19.0.2, mixed mode, sharing)
➜  projects node --version
v18.4.0
➜  projects yarn --version
1.22.19
➜  projects gem install solr_wrapper
Successfully installed solr_wrapper-4.0.2
Parsing documentation for solr_wrapper-4.0.2
Done installing documentation for solr_wrapper after 0 seconds
1 gem installed
➜  projects rails new search_app -m https://raw.github.com/projectblacklight/blacklight/main/template.demo.rb
[lots of creating and gem installing]
    generate  blacklight:assets
       rails  generate blacklight:assets
     gemfile  bootstrap (~> 4.0)
     gemfile  twitter-typeahead-rails (0.11.1.pre.corejavascript)
     gemfile  sassc-rails (~> 2.1)
      create  app/assets/javascripts/application.js
      append  app/assets/config/manifest.js
       exist  app/assets/images
      create  app/assets/stylesheets/blacklight.scss
     gemfile  jquery-rails
      insert  app/assets/javascripts/application.js
File unchanged! The supplied flag value not found!  app/assets/javascripts/application.js
[more creating and gem installing]
[ cd into search_app, start solr_wrapper, index test data]
bundle exec rails s
go to localhost:3000

What happens

When you try to start it, you get a stacktrace that includes

Completed 500 Internal Server Error in 368ms (ActiveRecord: 0.0ms | Allocations: 322933)

ActionView::Template::Error (wrong number of arguments (given 3, expected 1)):

app/assets/config/manifest.js:3

@seweissman found that when app/assets/config/manifest.js was generated, it had a strange looking line without a line break, and that by taking only a portion of that line, the application worked

Before (not working):

//= link_directory ../stylesheets .css

//= link application.js//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js

After (working):

//= link_tree ../images
//= link_directory ../stylesheets .css

//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js
@seweissman
Copy link

When I left the //= link application.js in and just added a line break I got another error :Error (Multiple files with the same output path cannot be linked ("application.js") (see below). I took out this line and the app loads but this may just be a temporary fix.

docker-registry-search-1  |   Rendering layout /usr/local/bundle/gems/blacklight-7.33.0/app/views/layouts/blacklight.html.erb
docker-registry-search-1  |   Rendering /usr/local/bundle/gems/blacklight-7.33.0/app/views/catalog/index.html.erb within layouts/blacklight
docker-registry-search-1  |   Rendered /usr/local/bundle/gems/blacklight-7.33.0/app/views/catalog/_facet_group.html.erb (Duration: 98.5ms | Allocations: 12963)
docker-registry-search-1  |   Rendered /usr/local/bundle/gems/blacklight-7.33.0/app/views/catalog/_facets.html.erb (Duration: 101.1ms | Allocations: 13524)
docker-registry-search-1  |   Rendered /usr/local/bundle/gems/blacklight-7.33.0/app/views/catalog/_search_sidebar.html.erb (Duration: 103.2ms | Allocations: 13786)
docker-registry-search-1  |   Rendered /usr/local/bundle/gems/blacklight-7.33.0/app/views/catalog/_home_text.html.erb (Duration: 0.7ms | Allocations: 430)
docker-registry-search-1  |   Rendered /usr/local/bundle/gems/blacklight-7.33.0/app/views/catalog/_home.html.erb (Duration: 2.8ms | Allocations: 713)
docker-registry-search-1  |   Rendered /usr/local/bundle/gems/blacklight-7.33.0/app/views/shared/_sitelinks_search_box.html.erb (Duration: 0.6ms | Allocations: 261)
docker-registry-search-1  |   Rendered /usr/local/bundle/gems/blacklight-7.33.0/app/views/catalog/index.html.erb within layouts/blacklight (Duration: 116.2ms | Allocations: 15987)
docker-registry-search-1  |   Rendering layouts/blacklight/base.html.erb
docker-registry-search-1  |   Rendered layouts/blacklight/base.html.erb (Duration: 7744.4ms | Allocations: 141652)
docker-registry-search-1  |   Rendered layout /usr/local/bundle/gems/blacklight-7.33.0/app/views/layouts/blacklight.html.erb (Duration: 7865.1ms | Allocations: 158272)
docker-registry-search-1  | Completed 500 Internal Server Error in 8347ms (ActiveRecord: 0.0ms | Allocations: 198657)
docker-registry-search-1  | 
docker-registry-search-1  | 
docker-registry-search-1  |   
docker-registry-search-1  | ActionView::Template::Error (Multiple files with the same output path cannot be linked ("application.js")
docker-registry-search-1  | In "/opt/asb/registry-search/app/assets/config/manifest.js" these files were linked:
docker-registry-search-1  |   - /opt/asb/registry-search/app/assets/javascripts/application.js
docker-registry-search-1  |   - /opt/asb/registry-search/app/javascript/application.js
docker-registry-search-1  | ):
docker-registry-search-1  |   
docker-registry-search-1  | sprockets (4.2.0) lib/sprockets/base.rb:100:in `find_all_linked_assets'
docker-registry-search-1  | sprockets (4.2.0) lib/sprockets/manifest.rb:125:in `each'
docker-registry-search-1  | sprockets (4.2.0) lib/sprockets/manifest.rb:125:in `to_a'
docker-registry-search-1  | sprockets (4.2.0) lib/sprockets/manifest.rb:125:in `block (2 levels) in find'
docker-registry-search-1  | concurrent-ruby (1.2.2) lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
docker-registry-search-1  | concurrent-ruby (1.2.2) lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:48:in `block in synchronize'
docker-registry-search-1  | concurrent-ruby (1.2.2) lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:48:in `synchronize'
docker-registry-search-1  | concurrent-ruby (1.2.2) lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:48:in `synchronize'
docker-registry-search-1  | concurrent-ruby (1.2.2) lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:22:in `execute'
docker-registry-search-1  | concurrent-ruby (1.2.2) lib/concurrent-ruby/concurrent/promise.rb:564:in `block in realize'
docker-registry-search-1  | concurrent-ruby (1.2.2) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:352:in `run_task'
docker-registry-search-1  | concurrent-ruby (1.2.2) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:343:in `block (3 levels) in create_worker'
docker-registry-search-1  | concurrent-ruby (1.2.2) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `loop'
docker-registry-search-1  | concurrent-ruby (1.2.2) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `block (2 levels) in create_worker'
docker-registry-search-1  | concurrent-ruby (1.2.2) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:333:in `catch'
docker-registry-search-1  | concurrent-ruby (1.2.2) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:333:in `block in create_worker'

@jcoyne
Copy link
Member

jcoyne commented Mar 7, 2023

I believe the double link error is because Blacklight 7.33 is not compatible with importmap, which is what rails 7 installs by default.

@tmarnell
Copy link

I'm trying to install Blacklight from the Quickstart guide as well. After starting the server, I received an error page like this:

Sprockets::Rails::Helper::AssetNotPrecompiledError in Catalog#index
Showing /home/(username)/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/blacklight-8.0.0/app/views/layouts/blacklight/base.html.erb where line #19 raised:
Asset blacklight/bookmark_toggle.js was not declared to be precompiled in production.
Declare links to your assets in app/assets/config/manifest.js.
//= link blacklight/bookmark_toggle.js
and restart your server

I added the link and restarted, but saw another error with a different link to add. This repeated a total of 8 times until all of these links were in the manifest file.

//= link blacklight/bookmark_toggle.js
//= link blacklight/button_focus.js
//= link blacklight/checkbox_submit.js
//= link blacklight/core.js
//= link blacklight/index.js
//= link blacklight/modal.js
//= link blacklight/modalForm.js
//= link blacklight/search_context.js

Finally the site will load, but it looks like plain HTML with no JS or CSS.

These scripts are listed in the file ~/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/blacklight-8.0.0/app/assets/javascripts/blacklight/blacklight.js.map, but it seems they're not being included or referenced properly somewhere.

@tmarnell
Copy link

tmarnell commented Apr 6, 2023

Follow-up: I restarted with a fresh environment and followed every step again from the beginning, with the same results. However, manually running rails generate blacklight:install from within the search_app project after installing it the "easy way" fixed the JavaScript compiling issue.

Here's the output from the manual install, in case it sheds light on what was missing: blacklight-install-output.txt

My environment:
ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
rails --version
Rails 7.0.4.3
java -version
openjdk version "11.0.18" 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu120.04.1)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu120.04.1, mixed mode, sharing)
node --version
v18.15.0
yarn --version
1.22.19

@ygorg
Copy link

ygorg commented May 31, 2023

From what I gathered, when installing the "easy way" blacklight:assets is performed before importmap:install. blacklight:assets tries to write to config/importmap.rb which does not yet exist. Resulting in @tmarnell's error (involving blacklight/bookmark_toggle.js)
When installing the "hard way", generating the app performs importmap:install so it works well.

Just in case: if generating a minimal app the hard way (--minimal) then blacklight:assets:sprockets is used and the error is similar to @tmarnell's one but involving application.js.

Error obtained
$ rails new tmp_app -m https://raw.github.com/projectblacklight/blacklight/main/template.demo.rb
[...]
    generate  blacklight:assets
       rails  generate blacklight:assets 
    generate  blacklight:assets:importmap
       rails  generate blacklight:assets:importmap --bootstrap-version='\~\>\ 5.1'
     gemfile  bootstrap (\~\>\ 5.1)
The file /home/path/to/tmp_app/config/importmap.rb does not appear to exist

append_to_file 'config/importmap.rb' do

Commented template.demo.rb :

# frozen_string_literal: true
gem 'blacklight', '>= 7.0'
# -> does 'blacklight:assets' but 'config/importmap.rb' not created
run "bundle install"

options = ENV.fetch("BLACKLIGHT_INSTALL_OPTIONS", '--devise --marc')
# -> does 'importmap:install' which creates 'config/importmap.rb'
generate 'blacklight:install', options
rake "db:migrate"

# -> Then we need to redo `rails generate blacklight:install` so 'blacklight:assets' is performed again

Hard way :

# does 'importmap:install' which creates 'config/importmap.rb'
rails new tmp_app
cd tmp_app
echo 'gem "blacklight", ">= 7.0"' >> Gemfile
bundle install
# does 'blacklight:assets' everything is great !
rails generate blacklight:install --devise --marc
rake db:migrate

@marlo-longley
Copy link
Contributor

This should be fixed via #3110

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants