Where do I start to investigate when phoenix live reload stops working after upgrading to Phoenix 1.0? - phoenix-framework

I just upgraded my project to Phoenix 1.0. For some reason phoenix live reload stopped working when I changed my files. Is there a place where I should look first to try to gain some insight on why it stopped working? Here is what my mix.exs looks like:
defp deps do
[{:phoenix, "~> 1.0"},
{:phoenix_html, "~> 2.1"},
{:phoenix_live_reload, "~> 1.0"},
{:cowboy, "~> 1.0"},
{:shouldi, only: :test},
{:meck, "~> 0.8.3"}]
end

Have you checked in your config/dev.exs file and seen (similar):
# Watch static and templates for browser reloading.
config :polyvox, Polyvox.Endpoint,
live_reload: [
patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
~r{web/views/.*(ex)$},
~r{web/templates/.*(eex)$}
]
]

Related

Phoenix - client requested channel transport error

While running my Phoenix app, I suddenly noticed an error being logged:
The client's requested channel transport version "2.0.0" does not match server's version requirements of "~> 1.0"
It appears after starting the server with mix phoenix.server:
[info] Running MyApp.Endpoint with Cowboy using http://localhost:4000
21 Nov 13:47:19 - info: compiled 4 files into app.js, copied robots.txt in 2.3 sec
[error] The client's requested channel transport version "2.0.0" does not match server's version requirements of "~> 1.0"
and then continues to log the error message every 10 seconds or so, regardless of whether or not I'm making any requests to the server. Despite this, the app seems to run fine, but it'd be great to resolve this.
Can anyone shed any light on why this would've suddenly started happening, and what I can do to fix it?
Here's some config info from mix.exs:
def application do
[mod: {MyApp, []},
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext,
:phoenix_ecto, :postgrex, :comeonin]]
end
defp deps do
[{:phoenix, "~> 1.2.1"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix_ecto, "~> 3.0"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.6"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"},
{:cors_plug, "~> 1.1"},
{:comeonin, "~> 3.0"},
{:guardian, "~> 0.14"},
{:guardian_db, "~> 0.8.0"}]
end

Using a built in sqlite3 database from a ruby gem

I'm currently building a gem that uses a sqlite3 database to store parsed content from a website. When I run the gem name in the command line, while I'm inside of it's original file directory, the program runs without any problems.
However, when I install the gem to another project and try to run it I get an error:
/usr/local/rvm/gems/ruby-2.3.1/gems/mtg-card-finder-0.1.1/config/environment.rb:8:in `initialize': unable to open database file (SQLite3::CantOpenException)
I have created the database file outside of the lib folder but it is referenced in my environment file:
require 'open-uri'
require 'sqlite3'
require "tco"
require "mechanize"
require "nokogiri"
require "require_all"
DB = {:conn => SQLite3::Database.new("db/cards.db")} #this gives me validation to reach the database that module Persistable interacts with
require_all 'lib/mtg_card_finder' #this allows me to simultaneously require everything in lib/mtg_card_finder
Which is then required by my main file inside lib:
require_relative '../config/environment'
module MTGCardFinder
end
This is my first time building a ruby gem, so I know that I must be messing something up on my gemspec, or some other thing that I don't know of that isn't allowing the database to be accessible when installed as just a gem.
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'mtg_card_finder/version.rb'
spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.executables << "mtg-card-finder"
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.14"
spec.add_development_dependency "rake", "~> 12.0"
spec.add_development_dependency "pry", "~> 0.10.4"
spec.add_dependency "rubysl-open-uri", "~> 2.0"
spec.add_dependency "nokogiri", "~> 1.7.1"
spec.add_dependency "tco", "~> 0.1.8"
spec.add_dependency "sqlite3", "~> 1.3.13"
spec.add_dependency "mechanize", "~> 2.7.5"
spec.add_dependency "require_all", "~> 1.4"
Any advice would be so welcoming! :)
Here is the repo if you need additional lines from the gemspec and such:
https://github.com/JuanGongora/mtg-card-finder
I found out what the problem was, first I had to do a simple rearrange in my main lib file:
module MTGCardFinder #needs to be defined first so that environment loads correctly
end
require_relative '../config/environment'
Before my environment was requiring particular files that were children of the module MTGCardFinder so it was responding with an uninitialized constant error, so I just had to define the module first so that the interpreter could read that before seeing what else was required.
Second fix was automatically making a directory that would contain the stored database, inside of the current directory where the gem would be installed. I had the original database folders within the gem but it wasn't accessing them, so this was the workaround:
require 'fileutils' # for creating the directory
DIR = "db"
FileUtils.makedirs(DIR)
DB = {:conn => SQLite3::Database.new("db/cards.db")} #this gives me validation to reach the database that module Persistable interacts with

Heroku Production - ActionView::Template::Error (undefined method `directory' for #<Sprockets::Manifest:number>)

We have a react-rails app. Unfortunately, the app works on local development but not when deployed to heroku. When going to our default path on the app, we get the following error:
ActionView::Template::Error (undefined method 'directory' for #<Sprockets::Manifest:0x007fef13200aa8>)
We've figured out that it happens at this line in our view:
<%= react_component('NavBar', {}, {prerender: true}) %>
A few things about our app:
It uses browserify to compile our js.jsx.
We precompile using RAILS_ENV=production bundle exec rake assets:precompile after deleting the public/assets folder.
Works locally with both rails s and foreman start
We are using boostrap-sprockets. Even when removed, we still have this issue.
Here is our npm dependencies:
"dependencies": {
"browserify": "^10.2.4",
"browserify-incremental": "^1.5.0",
"classnames": "^2.2.3",
"reactify": "^1.1.0"
}
Here is our Gemfile
source 'https://rubygems.org'
gem 'rails', '4.2.3'
gem 'rails-api'
gem 'spring', :group => :development
gem 'active_model_serializers', '~> 0.10.0.rc1'
gem 'pg'
gem 'devise'
gem 'puma'
gem 'twitter'
gem 'react-rails', '~> 1.0'
gem 'browserify-rails', '~> 0.9.1'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'sass-rails', '~> 5.0', '>= 5.0.4'
gem 'autoprefixer-rails'
group :test do
gem 'rspec-rails'
gem 'pry'
gem 'faker'
gem 'webmock'
end
group :development, :test do
gem 'factory_girl_rails'
end
group :production do
gem 'uglifier'
gem 'rails_12factor'
gem 'rspec'
end
ruby '2.2.4'
We would appreciate all help.
The solution from hours of searching on StackOverflow and github issues seems to be to remove
//= require react_ujs
from your application.js in your assets folder.
I ran into this same issue just today and followed the suggestions in: https://github.com/reactjs/react-rails/issues/443#issuecomment-180544359. I was still running into an error so for now I modified my heroku configurations (config/environments/staging.rb & config/environments/production.rb) to use
config.assets.compile = true
for now and server-side rendering worked fine. The react-rails folks said they have a pull request completed to fix this issue but I dont think it has been released yet.
Potentially relevant: rake assets:precompile undefined method directory? for nil:NilClass
This is an error that occurs when the Rails asset compiler (Sprockets) cannot find a directory that you've specified as the location of an asset for your project. My suggestion is to make sure that all your assets are being successfully deployed to heroku, and then check that your paths are set up correctly when you reference assets in your project for inclusion in a page.
Also see Eric C's answer pertaining to React-Rails specifically.
There was a bug in react-rails 1.6.0 which should be fixed in 1.6.1
Here's the patch:
https://github.com/reactjs/react-rails/pull/478
If the latest version doesn't work for you, please open an issue on the react-rails repo!

Heroku with ruby 1.9.3 causing many different crashes

I go to redeploy my heroku apps with a new gem in Gemfile and it crashes on startup
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require': libruby.so.1.9: cannot open shared object file: No such file or directory - /app/vendor/bundle/ruby/1.9.1/gems/bcrypt-ruby-3.0.1/lib/bcrypt_ext.so (LoadError)
This is happening no matter what branch I deploy (old stable ones...) and only fixes by doing a heroku rollback.
I believe this is caused by heroku recently updating their ruby 1.9.3 because I was having this issue Heroku app crashes with 'libruby.so.1.9: cannot open shared object file' . Removing the nokogiri gem stopped the exception I was getting but then there's still this. More similar errors occur when I add new gems.
The whole problem was solved by deploying to a new heroku app but that's not something I can just do on my production server.
Any ideas on fixing the issue or somehow "refreshing" my app?
my gemfile:
source "https://rubygems.org"
ruby "1.9.3"
gem "rails", "3.2.3"
gem "thin"
# Bundle edge Rails instead:
# gem "rails", :git => "git://github.com/rails/rails.git"
gem "mongoid"
gem "devise"
gem "haml"
gem "sass"
gem "exceptional"
gem "kaminari"
gem "mongoid_search"
#gem "nokogiri"
gem "bson_ext"
gem "heroku-mongo-backup"
gem "aws-s3"
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem "haml-rails", "~> 0.3.4"
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", :platform => :ruby
gem "uglifier", ">= 1.0.3"
end
gem "jquery-rails"
group :test do
gem "mongoid-rspec"
end
# 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 "ruby-debug19", :require => "ruby-debug"
#
group :development do
gem "letter_opener"
end
Just FYI,
After contacting the Heroku support about this issue, you should follow these 3 simple steps:
Install this heroku-repo plugin: heroku plugins:install https://github.com/lstoll/heroku-repo.git
Run the following command: heroku repo:purge_cache
Deploy your app again.
Hope that helps!
This happened to me yesterday as well, was definitely something to do with Heroku.
I found fix and discussion on Twitter: https://twitter.com/bcardarella/status/256822171979100161
Just force-clear the gem file cache(clear gemfile, deploy, restore and deploy) and the app would start smoothly again.

How to reduce heroku slug size?

My slug size is 89.5MB which is huge.
However the repository size is quite small:
$ du -hsc
8.0M .
8.0M total
Following this blog post: http://dazedthots.blogspot.com/2011/07/reducing-slug-size-heroku.html , there is a bug on Heroku with changing Gemfiles. Mine has changed several times including git dependencies but now, the only git dependency is "rails_admin". See below:
source 'http://rubygems.org'
gem 'rails', '~> 3.1.0'
gem 'rails-i18n', '~> 0.1.3'
gem 'pg', '~> 0.11.0'
gem 'rake', '~> 0.8.7'
gem 'thin', '~> 1.2.11'
gem 'heroku', '~> 2.4.0'
gem 'squeel', '~> 0.8.6'
gem 'devise', '~> 1.4.2'
gem 'slim-rails', '~> 0.2.0'
gem 'simple_form', '~> 1.4.2'
gem 'will_paginate', '~> 3.0'
gem 'sunspot_rails', '~> 1.2.1'
gem 'jquery-rails', '~> 1.0.12'
gem 'modernizr-rails', '~> 2.0.6'
gem 'rails_admin', git: 'https://github.com/sferik/rails_admin.git'
gem 'sass-rails', '~> 3.1.0'
gem 'coffee-rails', '~> 3.1.0'
gem 'uglifier', '~> 1.0.0'
gem 'newrelic_rpm'
I've contacted the Heroku support but no answer until now? Any idea?
Finally, after 3 days, Heroku cleaned up my cache.
Everything is fine now though my slug is still 54MB which seems too big.
Heroku confirmed there was no other solution than contacting them to resolve this issue. Hopefully, it will be resolved in a future version of bundler.
I've been able to trim a few megabytes here and there by listing directories in the .slugignore file. That may help you stay under the 100mb limit until this issue gets resolved.
You may also want to experiment with pushing your changes into a new repository without history, since it looks like Heroku is penalizing you with the full size of the cloned git tree that you are referencing.
Being as Heroku have acknowledged the problem in the post you have referenced I would wait and sit it out until Heroku have fixed it their end. I take it you've already looked into some of the other ways to reduce a slug size with a .slugignore file?
Slug size will include all your gems so the more gems you use the larger your slug size will be since each Heroku app maintains it's own gems these days. I'd not heard of :git referenced gems using more space but I have now though.
THE TRICK THAT FIXED THE PROBLEM FOR ME:
What works: I made another folder. I search for git in that folder. and I delete the files on the xml file and then I tried uploading to Heroku and it worked.
As with you, my ruby repo was only a fraction of my heroku slug size. I followed the advice of this heroku guide
to explore the uncompressed slug on my heroku dyno by running:
$ heroku run bash -a [app-name]
Most of my space was taken up by the gem source files under /vendors on heroku. These source files are not in my repo. I found a single 250MB binary file for a Gemfile dependency which I am in the process of replacing.

Resources