".js is not present in the asset pipeline" - ruby-on-rails

I know this is a very repeated question but I have done everything by the books, read a bunch of SO posts and none have helped so far.......
assets.rb
Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.paths << Rails.root.join('node_modules')
application.js:
//= require rails-ujs
//= require activestorage
//= require jquery3
//= require popper
//= require bootstrap-sprockets
//= require turbolinks
//= require_tree .
production.rb:
...
config.assets.js_compressor = Uglifier.new(harmony: true)
config.assets.compile = false
...
gems ( i assume can possible affect this):
gem 'webpacker'
gem 'react-rails'
gem 'bootstrap', '~> 4.3.1'
gem 'jquery-rails'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
application.rb:
require_relative 'boot'
require 'csv'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Shopify14
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2
config.serve_static_assets = true
# config.active_job.queue_adapter = :sidekiq
# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.
end
end
I tried adding application.js to the assets.rb file. (Even though it's already included), but that didn't work.
None of my app/assets/javascript/{} files will work with:
<%= javascript_include_tag "javascript.js" %> without the asset pipeline error message in the console.
I am using heroku
Is there something I am missing?
I would rather not directly add these files to the assets.rb file because these are mostly page specific js files i want to use.

Related

Rails Heroku Deployment Error: Precompiling assets failed – Sprockets::FileNotFound: couldn't find file 'angular' with type 'application/javascript'

My app works locally, however when I try to deploy to Heroku, I get a Sprockets::FileNotFound: couldn't find file 'angular' with type 'application/javascript' error.
I have tried precompiling with RAILS_ENV=production bundle exec rake assets:precompile and purging my build cache with heroku builds:cache:purge -a findum, but still no luck. I recently migrated from Bower to Yarn– not sure if my asset path is the problem?
Has anyone run into a similar error that they were able to resolve? So many thanks 🙏.
This is my application.js :
//= require lodash
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jqueryui-touch-punch
//= require cloudinary/jquery.fileupload
//= require cloudinary/jquery.cloudinary
//= require angular
//= require angular-resource
//= require angular-animate
//= require angular-bootstrap
//= require angular-sanitize
//= require angular-rails-templates
//= require_tree ../templates
//= require bootstrap
//= require external/picker
//= require external/picker.date
//= require angular-filter/dist/angular-filter
//= require swipebox
//= require angular-ui-sortable/sortable
//= require bootstrap-select/dist/js/bootstrap-select
//= require string-mask/src/string-mask
//= require_tree .
And Gemfile:
source 'https://rubygems.org'
gem 'rails', '~> 4.2.0'
gem 'active_model_serializers', '~>0.9.3'
gem 'angular-rails-templates'
gem 'responders', '~> 2.0'
gem 'angular_rails_csrf'
gem 'pg'
gem 'resque', require: "resque/server"
# gem 'resque-scheduler'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'sass-rails', '>= 3.2'
gem 'animate-scss'
gem 'swipebox'
gem 'rake', '< 11.0'
gem 'lodash-rails'
gem 'jquery-rails'
gem 'turbolinks'
# gem 'bcrypt-ruby', '3.0.1'
gem 'devise'
gem 'geocoder'
gem 'searchkick'
gem 'cloudinary'
gem 'httparty'
gem 'newrelic_rpm'
gem 'rack-cors', :require => 'rack/cors'
gem 'passenger'
gem 'uglifier'
gem 'rollbar'
gem 'figaro'
gem 'git'
gem 'mailchimp', '~> 0.0.9'
gem 'twitter'
gem 'friendly_id', '~> 5.1.0'
gem 'roo', git: "https://github.com/roo-rb/roo.git"
gem 'uuid'
gem 'awesome_print'
gem 'seed_dump'
gem 'mixpanel-ruby'
gem 'redcarpet'
group :production do
gem 'rails_12factor'
gem 'aws-sdk'
end
group :test, :development do
gem 'factory_bot_rails'
gem 'rspec-rails', '~> 3.2.0'
gem 'protractor-rails'
gem 'dotenv-rails'
end
group :test do
gem 'database_cleaner', '~> 1.3.0'
end
group :development do
gem 'annotate', '2.5.0'
gem 'better_errors'
gem 'binding_of_caller'
gem 'pry-byebug'
gem 'pry-rails'
gem 'twitter-console'
gem 'mailcatcher'
gem 'bullet'
end
ruby '2.2.2'
assets.rb
Rails.application.config.assets.precompile.shift
# Explicitly register the extensions we are interested in compiling
Rails.application.config.assets.precompile.push(Proc.new do |path|
File.extname(path).in? [
'.html', '.erb', # Templates
'.png', '.gif', '.jpg', '.jpeg', '.svg', # Images
'.eot', '.otf', '.svc', '.woff', '.ttf', # Fonts
]
end)
# Precompile additional assets
Rails.application.config.assets.precompile += ['private_beta.css', 'admin/admin.js', 'admin/admins.css']
My package.json looks like this:
{
"name": "Findum",
"version": "0.0.1",
"repository": {
"type": "git",
"url": "https://github.com/findum/findum.git"
},
"engines": {
"node": "14.x",
"yarn": ">= 1.0.0"
},
"scripts": {
"postinstall": "node -e \"try { require('fs').symlinkSync(require('path').resolve('node_modules/#bower_components'), 'vendor/assets/bower_components', 'junction') } catch (e) { }\""
},
"dependencies": {
"#bower_components/angular": "angular/bower-angular#1.2.32",
"#bower_components/angular-animate": "angular/bower-angular-animate#~1.2.27",
"#bower_components/angular-bootstrap": "angular-ui/bootstrap-bower#~0.12.0",
"#bower_components/angular-filter": "a8m/angular-filter#*",
"#bower_components/angular-resource": "angular/bower-angular-resource#~1.2.27",
"#bower_components/angular-sanitize": "angular/bower-angular-sanitize#~1.2.27",
"#bower_components/angular-ui-sortable": "angular-ui/ui-sortable#~0.13.3",
"#bower_components/bootstrap-select": "snapappointments/bootstrap-select#1.6.4",
"#bower_components/font-awesome": "FortAwesome/Font-Awesome#~4.2.0",
"#bower_components/jquery": "jquery/jquery-dist#~2.1.3",
"#bower_components/jquery-ui": "components/jqueryui#~1.11.2",
"#bower_components/jquery-ujs": "rails/jquery-ujs#1.0.3",
"#bower_components/jqueryui-touch-punch": "furf/jquery-ui-touch-punch#*",
"#bower_components/lodash": "lodash/lodash#~2.4.1",
"#bower_components/spin.js": "fgnass/spin.js#~2.0.1",
"#bower_components/string-mask": "the-darc/string-mask#0.2.0",
"bower": "~1.3.11",
"jquery": "^3.5.1"
}
}
And my application.rb:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
require 'csv'
Bundler.require(:default, Rails.env)
module Findum
class Application < Rails::Application
config.time_zone = 'Eastern Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.encoding = "utf-8"
config.filter_parameters += [:password]
config.active_support.escape_html_entities_in_json = true
config.active_record.schema_format = :sql
config.active_record.raise_in_transactional_callbacks = true
config.assets.enabled = true
config.assets.version = '1.0'
config.assets.initialize_on_precompile = false
# Add the fonts path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
# Add Bower components
config.assets.paths << Rails.root.join('vendor', 'assets', 'bower_components')
config.secret_key_base = 'findum'
config.eager_load = false
config.autoload_paths += Dir[Rails.root.join('app', 'models', '**/')]
config.autoload_paths += Dir["#{config.root}/lib/**/"]
config.i18n.enforce_available_locales = true
end
end
Update:
It looks like it was a problem with my post-Bower configuration (I migrated from Bower --> Yarn) I was able to solve Sprockets errors by adding this line to my assets.rb:
Rails.application.config.assets.paths << Rails.root.join('node_modules')
and by running yarn add <package name> for files that Sprockets could not locate.
I also made the following updates to old package names in my `application.rb'
//= require lodash
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require cloudinary/jquery.fileupload
//= require cloudinary/jquery.cloudinary
//= require angular
//= require angular-resource
//= require angular-animate
//= require angular-bootstrap
//= require angular-sanitize
//= require angular-rails-templates
//= require_tree ../templates
//= require bootstrap
//= require external/picker
//= require external/picker.date
//= require angular-filter/dist/angular-filter
//= require swipebox
//= require angular-ui-sortable
//= require bootstrap-select
//= require string-mask/src/string-mask
//= require_tree .

couldn't find file 'jquery.ui.core' in rails 4 while trying to change design look of the datatable

This is the application.css
*= require bootstrap
*= require jquery.ui.core
*= require jquery.ui.theme
*= require dataTables/src/demo_table_jui
*= require admin/taluks
*= require bootstrap-submenu.min
This is the application.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require bootstrap.min
//= require bootstrap-submenu.min
//= require dataTables/jquery.dataTables
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
//= require jquery-ui/datepicker
//= require data-confirm-modal
//= require admin/taluks
//= require admin/ceos
//= require admin/progress_charters
//= require admin/societies
//= require turbolinks
This is the gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.6'
# Use sqlite3 as the database for Active Record
gem 'mysql2'
gem 'devise'
gem "cancan"
gem 'carrierwave'
gem "mini_magick"
gem 'data-confirm-modal', github: 'ifad/data-confirm-modal'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'jquery-datatables-rails', '~> 3.1.1'
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-ui-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
gem 'bootstrap-sass', '~> 3.2.0'
gem 'autoprefixer-rails'
I tried downgrading jquery-rails to 'jquery-rails', "~> 2.3.0". But it's not helping. I restarted server. Cleaned assets and cleaned bundle
I had the same issue than you right now with the latest version of query-ui-rails. I suppose that you followed the railscast on datable, if so then I invite you to the query-rails-ui Github. The rails cast is a bit outdated.
Now if you want to include specific module you would have to write:
*= require jquery-ui/core
*= require jquery-ui/theme

Rails error include jquery.ui.all

I have an error when I try to include jquery.ui.all. All worked perfectly befor that I reboot my computer but now I have this error :
couldn't find file 'jquery.ui.all'
I rebooted my server, I try to clear the cache from the Rails console and on my navigators and I still have the problem. I also tried to to delete the Gemfile.lock and run bundle install and still the same error.
Here my both application.js and application.css :
//= require ./plugins/jquery-1.10.2.min
//= require jquery_ujs
//= require fullcalendar
//= require jquery.ui.all
//= require ./plugins/jquery-migrate-1.2.1.min
//= require ./plugins/bootstrap/js/bootstrap.min
//= require turbolinks
//= require underscore-min
//= require gmaps_google
*= require_self
*
* CSS Global Compulsory
*= require ./plugins/bootstrap/css/bootstrap.min
*= require style
*
* CSS Implementing Plugins
*= require ./plugins/line-icons/line-icons
*= require ./plugins/font-awesome/css/font-awesome.min
*= require ./plugins/flexslider/flexslider
*= require ./plugins/bxslider/jquery.bxslider
*= require ./plugins/layer_slider/css/layerslider
*= require ./plugins/hover-effect/css/custom-hover-effects
*= require ./plugins/sky-forms/version-2.0.1/css/custom-sky-forms
*
* CSS Theme
*= require ./themes/orange.css
*
* CSS Customization
*= require custom
*= require fullcalendar
*= require jquery.ui.all
*/
And my Gemfile :
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use mysql2 as the database for Active Record
gem "mysql2", "~> 0.3.15"
# gem "mysql2", "0.3.11"
# Use PostgreSql at the database for Active Record
gem "pg"
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-ui-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Bundle Pagination
gem 'will_paginate', '~> 3.0'
gem 'will_paginate-bootstrap'
# Authentification, Authorize, Roling
gem 'omniauth'
gem 'devise'
gem 'omniauth-google-oauth2'
gem 'cancan'
gem 'rolify', :git => "git://github.com/EppO/rolify.git"
# Géolocalisation
gem 'geocoder'
gem 'gmaps4rails'
# API Builder
gem 'rabl'
# Json Parser
gem 'oj'
# Upload de Fichier
gem "paperclip", "~> 4.1"
# Fullcalendar
gem 'fullcalendar-rails'
Ok I find the problem,
The problem is from the update of the gem jquery-ui-rails. Befor the include was :
jquery.ui.all
and now :
jquery-ui
Hope that it can me helpful

Datatable works in development mode, but doens't work in production - assets

I have a problem, I think my problem is with assets, because it works in Development environment but does not work in Production.
I'm using DataTables in my app, it's works in development mode.
I follow all steps in this link:
https://github.com/rweng/jquery-datatables-rails
I searched for answers and I found many posts. I tried all, but still could not solve the issue.
P.S.: If I execute: RAILS_ENV=production bundle exec rake assets:precompile, datatable stops working in development mode too.
in Gemfile:
source 'https://rubygems.org'
gem 'rails', '~> 3.2.16'
gem 'mysql2', '~> 0.3.14'
# Autenticação
gem 'authlogic', '~> 3.3.0'
# Autorização
gem 'cancan'
# Anexos
gem 'paperclip', '~> 3.0'
# Mailer
gem 'mail', '~> 2.5.4'
# Custom select
gem "bootstrap-select-rails", "~> 1.3.0"
#
gem 'whenever', :require => false
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '~> 1.0.3'
gem 'therubyracer', '~> 0.12.0'
end
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
gem 'less-rails'
gem 'jquery-rails'
gem 'jquery-ui-rails', '~> 4.1.1'
# twitter bootstrap css & javascript toolkit
gem 'twitter-bootswatch-rails', '~> 3.0.3'
# twitter bootstrap helpers gem, e.g., alerts etc...
gem 'twitter-bootswatch-rails-helpers'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
assets/javascripts/aplication.js
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require jquery.ui.all
//= require jquery.ui.tabs
//= require jquery.ui.tabs.min
//= require bootstrap-tabs
//= require interns
//= require systems_analysts
//= require generics
//= require file_field
//= require bootstrap-filestyle
//= require dataTables/jquery.dataTables
//= require dataTables/jquery.dataTables.bootstrap
//= require cocoon
assets/javascripts/interns.js
// Ordenação dos Grids por coluna
$(document).ready(function() {
$('#hr_curriculum_interns').dataTable({
"aoColumnDefs": [ // Ordenação desativada nas colunas com actions
{ 'bSortable': false, 'aTargets': [ 5, 6, 7, 8 ] }
],
"bPaginate": false,
"bFilter": false,
"bInfo": false
});}
);
assets/stylesheets/application.css
/* Cerulean
* Bootswatch
*= require_self
*= require jquery.ui.all
*= require cerulean/loader
*= require cerulean/bootswatch
*= require_tree ./custom/
*= require jquery.ui.theme
*= require jquery.ui.core
*= require dataTables/jquery.dataTables.bootstrap
*/
Any idea please?
Your issue is probably because of Rails Asset pipelining in production.
Try this..........
In config/initializers
config.assets.precompile += %w( *.js *.css )
and In environments/production.rb
config.serve_static_assets = true
then
RAILS_ENV=production rake assets:precompile
then check
RAILS_ENV=production rails s

Precompiling assets doesn't seem to be working

I'm having a strange problem that I have never encountered when deploying my rails apps to production.
I run:
bundle exec rake assets:precompile
This is the output:
/home/ubuntu/.rvm/rubies/ruby-2.0.0-p0/bin/ruby /home/ubuntu/.rvm/gems/ruby-2.0.0-p0/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
/home/ubuntu/.rvm/rubies/ruby-2.0.0-p0/bin/ruby /home/ubuntu/.rvm/gems/ruby-2.0.0-p0/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
This is my app/assets/javascripts/application.js:
//= require jquery
//= require jquery_ujs
//= require jquery.ui.all
//= require twitter/bootstrap
//= require_tree .
And this is my app/assets/stylesheets/application.css:
/*
*= require_self
*= require jquery.ui.all
*= require_tree .
*/
After I precompile, this is my public/assets/application-946a5a61f067fe19fe65ffd12f8c4a20.js
//= require jquery
//= require jquery_ujs
//= require jquery.ui.all
//= require twitter/bootstrap
//= require_tree .
So it's exactly the same as the original file.
And public/assets/application-df7525e917401704ef453cb56bf16697.css is an empty file.
This is my Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem 'settingslogic'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'json'
gem 'will_paginate', '~>3.0.pre2'
gem 'friendly_id', '~> 4.0.0.beta14'
gem 'rails3-jquery-autocomplete'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
gem 'paperclip', '~> 3.0'
gem 'public_activity'
gem 'rails-timeago'
gem 'therubyracer', :require => 'v8'
gem 'less-rails'
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier', '>= 1.0.3'
end
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
And config/environments/production.rb:
Yupp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
#config.assets.initialize_on_precompile = false
#...
end
Any direction will be greatly appreciated.
What solved the problem for me :
set the last rails version in Gemfile (3.2.14 for now)
bundle update
bundle install
restart the app touch tmp/restart.txt
I spent 2 hours on this then I found https://github.com/sstephenson/sprockets/issues/352
I tried downgrade ruby to 1.9.3 and do precompile then add compiled files to repo.. This isn't what I want but it works..
Update: what rails version are you using ? I was using 3.2.2 which has problem like this. 3.2.13 works fine(with ruby 2.0).

Resources