rails and metronic - assets precompile: SassC error, not enough space - ruby-on-rails

I have developed a rails app, based on bootstrap. Now I'm using Metronic to improve the stylings but while I don't have any problem in development mode, trying to compile assets in production mode, I get this error:
rake aborted!
SassC::SyntaxError: Internal Error: Not enough space
/home/spanogi/.rbenv/versions/2.4.3/bin/bundle:23:in 'load'
/home/spanogi/.rbenv/versions/2.4.3/bin/bundle:23:in ''
Tasks: TOP => assets:precompile
the command I issue is
bundle exec rake assets:precompile RAILS_ENV=production
If I do not add Metronic assets to my application.scss and application.js precompilation regularly finishes.
The server resources seems to be abundant, I checked memory while compiling but it doesn't go over 30% of usage and in fact the error is generated internally by Sassc, not by the OS (it's not a memory crash). I looked for similar errors around but did not have any success.
Do you have ideas? Thank you so much for your help

I managed to get it work.
I discovered that in SassC package "Not enough space" means "No UTF-8 encoded file"... (at least in my case) so all I had to do has been to convert the file to UTF-8 coding. I used this command (LINUX):
iconv -f UTF-8 -t ascii//TRANSLIT filename -o output_file_name
then I had to clean the file from some "\0"s and everything worked.
Hope this could be useful to someone!

I just remove \0 from the css file and worked well

Related

Heroku deploy fails to load custom .bundle file

I'm having a lot of trouble googling this issue, as bundler keeps coming up. However, my issue is with a c library that I've bundled using mkmf and the ruby c api. I've compiled my c code into a file (e.g. my_library.bundle) and I've required it inside a helper with require_relative "my_library" without a problem.
The problem arrises when I deploy to heroku and I get the error:
2019-08-14T19:09:15.452530+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require': cannot load such file -- /app/app/helpers/my_library (LoadError)
I can run ls and cat on my heroku app to verify the file is there and the contents match. When I run the application locally with RAILS_ENV=production, I also don't run into any issues. Also, running heroku local web runs fine on my machine.
Does this have something to do with my configs autoload_paths? My main issue is that I can't seem to debug this locally.
EDIT:
I've noticed that this problem arrises in dockerized instances, as well. It seems that something about containerization seems to be the problem. I've even tried creating a gem to contain the bundle following this guide, which works locally, but again has the same issue finding the file, but this time the path is relative to the gem, not my project. I'm still stumped on what is causing this issue.
According to the error that you posted, it seems that Docker doesn't point to the correct path cannot load such file -- /app/app/helpers/my_library. If that is correct, you should explicitly specify the working directory in your Dockerfile.
WORKDIR /path/to/project
After that, just rebuild the image.
Now, if this doesn't work, you can check autoload_paths in your project or customize bootsnap to avoid error in autoloading paths.
What you can do is have the entire my_library as a local gem and point your Gemfile to it.
Roughly, the outline would be as follows:
Place the entire code for my_library in directory within your app, say fixtures (which is at the same level as your Gemfile.)
app/
...
fixtures/
my_library/
ext/
...
lib/
...
my_library.gemspec
Rakefile
Gemfile
Point your Gemfile to the my_library gem:
gem 'my_library', path: 'fixtures/my_library'
Then simply update your Gemfile.lock by running
bundle update
As #jay-dorsey mentioned, the bundle did need to be compiled on the server that was deploying the application in order to be used. Both of the guides that I followed to create the gem had some misinformation.
The gem should contain only the source files, no compiled source files
The rakefile should reference ext.lib_dir = "lib/my_library" instead of the ext directory
The gemspec should add the rake-compiler development dependency BEFORE the other dependencies
The version files should NOT try to load the extension, as it's being used in the gemspec, which is called before the gem has a chance to be compiled by rake / bundler
.bundle files can't be read on linux machines

SASS: After every change have to reboot my server

Using: rails4 app
Command: For Connecting and Rebooting in order to see the change.
rake assets:precompile
and
control + c
rails s
Is it normal!! Because, sometime I have to do a lot of change and I don't want to reboot the rails server 2000 times per hour.
It's development machine.
Suggestions would be appreciated.
I'm not sure why you're precompiling while still making changes to your SASS.
During development, if making frequent changes to SASS, I'll have cleaned my assets out and the server will pick up and compile these changes as I make them.
rake assets:precompile
is only used when I push to production
There is some guidance here: http://guides.rubyonrails.org/asset_pipeline.html#local-precompilation on why you might want to precompile locally, but I can't speak for your own projects.
I had a lot of headaches when trying to edit js files and refresh them while my assets were precompiled and they all went away went I ditched it in dev.
I solve it with this command
rake assets:clobber
Thanks anyway.

/usr/bin/env: ruby.exe: No such file or directory

I'm brand new to Rails and am following this tutorial on how to make Rails applications. I can't get the database to migrate to my heroku apps.
I'm currently at the beginning of chapter 3, trying to set up an app to use for the rest of the course.
I've been following the tutorial perfectly, and, so far, I've already built two apps and deployed them to heroku and migrated the data just fine, but the third time it's not working.
I was able to make the heroku page and push the app to it, but I just can't migrate the data.
I typed:
heroku run rake db:migrate
and got this error:
/usr/bin/env: ruby.exe: No such file or directory.
I'm assuming this means it's looking for the file in that directory and not finding it. How do I change where it's looking?
I checked "windows heroku run rake db:migrate error “/usr/bin/env: ruby.exe: No such file or directory”" and did what the answers recommended, that is, change "ruby.exe" to "ruby" in bin/bundle, bin/rails, and bin/rake, but that didn't work.
Any other tips? I have been stuck on this for hours. Thank you so much in advance.
The command is normally heroku run rake db:migrate. You should try that instead of heroku run rails db:migrate.
Make sure you've pushed your app to heroku. When it's pushing to heroku, make sure that it is also detected as a rails app. It's possible that heroku isn't detecting a rails app so the environment it sets up doesn't have ruby installed. But it may just be the error in the command name (rails instead of rake).
I had a similar problem on a repository I had ported over from windows.
It turns out that several scripts in the app's bin directory still had a shebang lines (#!/usr/bin/env ruby.exe) to ruby.exe instead of ruby. Once I fixed these scripts the problem went away.
On your local dev machine, before committing to git (and then pushing to Heroku), try changing the line endings to Unix line endings (rather than Windows line endings). On a *nix machine you'd do that by running dos2unix myfile.rb
If the line endings are wrong, the Linux loaded on Heroku will look for ruby^M and not for ruby, and will of course not find it, and give this exact error message.

rake assets precompile failed

When I run bundle exec rake assets:precompile --trace, my precompilation fails but I cannot see any specific reason for it.
See this pastebin for my output: http://pastebin.com/zggZyPyM
Precompiling assets takes a lot of memory. ~=400mb in my case. It might be possible that OS is killing of the process due to excessive memory usage. You can check the syslog to verify if that is the case.
You can increase the memory of your server to avoid the situation. If that is not possible, I would suggest that you precompile assets on your local system, commit them to the repo and deploy to the server. That way you wouldn't have to compile assets on your server. However you might want to look into ways to delete the previously generated assets somehow and also automate the process.
, but issue was resolvedI tried installing node.js first. And then, ran the following command bundle exec rake assets:precompile. Only then I didn't notice the error.
Initially, I thought it was because of low memory too. Cleaned almost all running applications, but couldn't find a solution. Plus, I opened Ruby as administrator. Not sure if that helped too, but issue was resolved.
This issue can also be resolved by using a node.js JS runtime to precompile assets as it apparently has a lower memory footprint. For Ubunutu 14.04 I needed to run apt-get install nodejs, then replace the default js runtime in the Gemfile with gem 'node', run bundleand finally rerun the precompile. I would caution against precompiling in another location as you may forget to do this after a css or js change, leading to errors.

Deploy to heroku generating plugin deprecation warning, but no plugins exist

I'm running into difficulties deploying a Rail app to Heroku. I'd really appreciate a check list of ideas to run through to sort this out, I've exhausted my ideas are am resorting to pulling my hair out!
The short story: heroku run rake db:migrate generates an error:
Running rake db:migrate attached to terminal... up, run.1
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/01/04/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/01/04/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
rake aborted!
syntax error on line 7, col 11: `'
This looks like it should be pretty easy to fix. The problem is, I don't have any plugins!
The long story: I'm getting ready to redeploy a Rails app for staging. This was a Rails 3.0 app on Heroku, which I've just completed a major upgrade on, including upgrade to Rails 3.2, Ruby 1.9.2, removal of plugins, and major rewrite. I'm now trying to push to Heroku's cedar stack to do some more testing.
I've been trying to work through this issue for a couple of days, and keep thinking I'm getting somewhere, but am then disappointed. Most recently I thought that my git repos were out of alignment and that the Heroku remote contained an old commit with these plugins. I no longer think this is the case. (I did want to check this, but am unable to get into Heroku console to verify the file structure, because of this error).
To confirm, my vendor/plugins folder is definitely empty on my local master and remote github repo. It should be empty on the remote Heroku branch as I've pushed all updates (I even created a completely blank app with a new remote name to test, but got the same error). I say vendor/plugins is empty, but actually vendor/plugins does not exist, having been fully deleted after I removed plugins within.
I did have two plugins installed in the app in an earlier version: HABTM checkboxes and fancybox-rails. These have both been uninstalled rails plugin remove <<plugin name>>.
I've checked the file referenced in the error /app/rakefile:7, but can't see anything wrong with this line MyApp::Application.load_tasks.
If I try to launch heroku console, the error is slightly different and references /app/config/environment.rb:5). I can't see anything here either MyApp::Application.initialize!
I've been through all the likely places looking for any remnants of these plugins or old require statements, and turned up nothing.
I'd really appreciate any ideas as to where else I can look. I can provide more information if needed, I'm simply not sure what's is useful at this stage!!
Thanks for helping me keep my hair!!
EDIT
I'm adding the full contents of the rakefile that is referred to in the error. I can't see any issues with this.
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require 'rake'
MyApp::Application.load_tasks
After a lot of hair pulling and frustration, I finally tracked this down to the following entry in the logs
/usr/local/lib/ruby/1.9.1/syck.rb:135:in `load': syntax error on line 7, col 11: `' (ArgumentError)
syck.rb parses yaml files, and low and behold I had a (minor) issue with a yaml file omitting some environment specific info.
For more detail, see this SO question.
The plugin deprecation warnings are from plugins Heroku injectes into your application at build time so it runs appropriately on the platform. Those can be ignored.
The crux of the issue appears to be related to a syntax error in your source/rake file. Here's the important output:
rake aborted!
syntax error on line 7, col 11: `'
Look at line 7 of the file the error originates from (post the rest of the stack trace for our reference?) and you'll find some sort of syntax error that needs to be fixed.
If you want to clearly separate the plugin loading and app load-time you use heroku run bash to load a shell and then run the rake task to see its output isolated:
$ heroku run bash
> bundle exec rake db:migrate
Hope that helps.
I read somewhere that heroku uses plugins to automate some tasks... so it's not your fault
If you want to silence the deprecation warnings, use this little snippet:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
ActiveSupport::Deprecation.silence do
Selfcare::Application.initialize!
end

Resources