Rails: Production assets:precompile error - ruby-on-rails-4

I am trying to deploy my app on Heroku but I don't know why the bellow error occurs.
I have gem 'rails_12factor', group: :production so I don't use config.serve_static_assets = true and config.assets.initialize_on_precompile as in the documentation explained that they are not needed in Rails 4.
When I execute these two commands respectively:
bundle exec rake assets:precompile
RAILS_ENV=production bundle exec rake assets:precompile
I get this error.
DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly. (called from block in tsort_each at /usr/local/lib/ruby/2.2.0/tsort.rb:226)
I, [2016-06-14T13:21:21.336814 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/font-awesome.min-1c15db9e10c99a36820b80616445a837a002b3f3969047f3375fba65f8fef2ba.css
I, [2016-06-14T13:21:21.337563 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/font-awesome.min-1c15db9e10c99a36820b80616445a837a002b3f3969047f3375fba65f8fef2ba.css.gz
I, [2016-06-14T13:21:21.341449 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/bootstrap.min-139ad6ac9cbd7b8cd15fa3f80b9b69e3ead570cb9686b3bb42b73a19ed62dcef.css
I, [2016-06-14T13:21:21.343432 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/bootstrap.min-139ad6ac9cbd7b8cd15fa3f80b9b69e3ead570cb9686b3bb42b73a19ed62dcef.css.gz
I, [2016-06-14T13:21:21.400914 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/jquery.fancybox-9eb4dcf39f4ad63c3bff3f55e2a0e5e8a32578cc4553c94633ce0ccdc08c2bea.css
I, [2016-06-14T13:21:21.401335 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/jquery.fancybox-9eb4dcf39f4ad63c3bff3f55e2a0e5e8a32578cc4553c94633ce0ccdc08c2bea.css.gz
I, [2016-06-14T13:21:21.405283 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/animate-0af100ee0144b8c4dc6de8605097b0920d4ea4aad067cc34fbaa7ab525d4e6a8.css
I, [2016-06-14T13:21:21.405707 #10455] INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/animate-0af100ee0144b8c4dc6de8605097b0920d4ea4aad067cc34fbaa7ab525d4e6a8.css.gz
rake aborted!
Sass::SyntaxError: Invalid CSS after "}": expected selector or at-rule, was "}"
(sass):86
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
I debugged and checked one of the files but I couldn't find any error like forgetting to use ), } or ; . Also, I cleaned the whole content of one of them and replace it by a simple CSS rule, but still I get the error!!
This error is also happening when I try to push my app to Heroku. Please, help me to understand what is the reason and its solution??

This is the answer I found, wishing it to be useful for others, too.
To solve the DEPRECATION WARNING, update your gems as expressed by:
Asset pipeline DEPRECATION WARNING tsort.rb:226
And about the main error, you should find which file causes the error exactly. The error output and mentioned files in it are misleading and not necessarily contain syntax error.
You can work with your assets.rb file to find which file (files) contains syntax error. Comment or remove all of the referred files in assets.rb except one, redo asset precompile command in your production mode:
RAILS_ENV=production bundle exec rake assets:precompile
and repeat it for all other css files to understand which one contains the error. This time the output of this command will be helpful and refer exactly to the problem. Then, it would be easy to find the error and fix it.

Related

Getting error while building project "com.bea.util.jam.internal.javadoc.JavadocClassloadingException:"

I am getting error while trying to build a java project in TeamCity. The same project builds and excecutes well on my local. I recently pushed changes to this project on GitLab. This is my first time working with GitLab and TeamCity together. Other projects have no issues during build. I am unable to understand what is causing this error:
[15:58:54][Step 1/1] compile.earCommons (4s)
[15:58:54][compile.earCommons] echo
[15:58:54][compile.earCommons] echo
[15:58:54][compile.earCommons] wlcompile (4s)
[15:58:59][wlcompile]
com.bea.util.jam.internal.javadoc.JavadocClassloadingException: An error
has occurred while invoking javadoc to inspect your source
files. This may be due to the fact that $JAVA_HOME/lib/tools.jar does
not seem to be in your system classloader. One common case in which
this happens is when using the 'ant' tool, which uses a special
context classloader to load classes from tools.jar.
This situation elicits what is believed to a javadoc bug in the initial
release of JDK 1.6. Javadoc attempts to use its own context classloader
tools.jar but ignores one that may have already been set, which leads
to some classes being loaded into two different classloaders. The
telltale sign of this problem is a javadoc error message saying that
'languageVersion() must return LanguageVersion - you might see this
message in your process' output.
This will hopefully be fixed in a later release of JDK 1.6; if a new
version of 1.6 has become available, you might be able to solve this
by simply upgrading to the latest JDK.
Alternatively, you can work around it by simply including
$JAVA_HOME/lib/tools.jar in the java -classpath
parameter. If you are running ant, you will need to modify the standard
ant script to include tools.jar in the -classpath.
[15:58:59][Step 1/1] Process exited with code 1
[15:58:59][Step 1/1] Ant output
[15:59:10][Step 1/1] Process exited with code 1 (Step: Ant)
[15:58:59][Step 1/1] Step Ant failed
****Update****
Build Step: Ant
Step 1:
Runner type: Ant (Runner for Ant build.xml files)
Execute: If all previous steps finished successfully
build.xml file: \ant\build.xml
Working directory: same as checkout directory
Targets: none specified
Ant home path: C:\apache-ant-1.7.0
Additional Ant command line parameters: -lib c:\WebLogic\12.1.2\wlserver\server\lib\javaee.jar;c:\WebLogic\12.1.2\wlserver\server\lib\weblogic.jar;c:\WebLogic\12.1.2\wlserver\server\lib\webservices.jar
JDK home path: c:\Program Files\Java\jdk1.7.0_80
JVM command line parameters: not specified
Reduce test failure feedback time: OFF
Java code coverage: disabled
Docker Settings
Docker Image: unset
I'll appreciate any help in this regard.
I found there was character encoding issue with one of the files that prevented compiler from loading the java classes. Once that was fixed, the build worked fine.

How to debug asset precompilation errors in Rails?

Command: (ran in console on local environment)
RAILS_ENV=production bundle exec rake assets:precompile --trace
What happens:
A lot of assets get precompiled. Suddenly precompilation stops with error.
I, [2017-06-08T15:31:19.726874 #31286] INFO -- : Writing /path/jquery.min-23476(...)79529.map
rake aborted!
ExecJS::RuntimeError: SyntaxError: Unexpected character '`' (line: 5185, col: 10, pos: 1741977)
Error
at new JS_Parse_Error (/private/var/folders/qz/8thdm5t122s725szpkpsxcdr0000gn/T/execjs20170608-31286-1f6tv61js:3623:11948)
How do you approach debugging of such a challenge?
This issue is due to ES6 Template literals are not being detected properly. A workaround would be replacing template literals with single quotes.
A very good example of this can be seen here

Rails 4 asset pipeline in production

My Rails app that I am upgrading to 4.2 from 3.2 has strange behavior in regards to the asset pipeline.
The guide says to use: RAILS_ENV=production bin/rake assets:precompile which causes this error:
Sass::SyntaxError: $red: "CC" is not a number for `rgba'
(sass):86
ArgumentError: $red: "CC" is not a number
The --trace doesn't point to any of my files and odder still is that I don't have any sass files to begin with.
I ran it without the RAILS_ENV and it compiled without complaint and everything seems to work.
My app has multiple layouts and themes which made for a slightly more complex and verbose set of asset manifests.
My question is, even though it seems to work is using that rake task without the RAILS_ENV=production going to cause issues?
It looks like you are actually sending an incorrect value to the sass compiler. Grep the code for $red or rgba and enter a correct list of numbers for the rgba statement that is causing the error.

Overriding rake task fails after upgrading to rails 4

I am trying to upgrade my app from rails 3.2.18 to rails 4.0 and I'm stuck on an issue with rake.
I have a custom doc.rake task that overrides doc:app with the following code inside that worked fine on rails 3:
# Replace Rails' rake doc:app with ours, which uses yardoc
Rake::Task["doc:app"].clear.enhance do
# Uses .yardopts_app file in rails root
app_dir = 'doc/generated/app'
sh "rm -rf #{app_dir}"
sh "bundle exec yardoc --plugin rails --yardopts .yardopts_app"
app_doc_files_dir = "#{app_dir}/doc-files"
Dir.mkdir( app_doc_files_dir )
cp_r( 'doc/files/app/doc-files/.', app_doc_files_dir )
end
Since upgrading rails, any rake task I try to run fails with the error:
rake aborted!
Don't know how to build task 'doc:app'
I'm really at a loss as to why this is happening. I can't find any reference to rails 4 removing the default doc:app task, so it should still exist for me to overwrite.
I was able to solve this by adding
require 'rails/tasks'
to the top of my rake file. So my full rake file looks like this now:
require 'rdoc/task'
require 'rails/tasks'
Rake::Task["doc:app"].clear
namespace :doc do
RDoc::Task.new('app') do |rdoc|
...
end
end

Unable to load a csv file into a rake task

Even when the command prompt is inside the lib/tasks directory, it simply responds "No such file or directory" when given the command rake populate
Direcory Structure
lib/tasks
seed.rake
type.csv
Files
seed.rake :
task :populate do
require 'csv'
CSV.foreach('type.csv', headers: true) do |row|
puts line
end
end
type.csv :
"26","Accessories"
"24","Activ8"
"17","Bandages"
"29","Biohazard"
"1","BS8599-1 First Aid Kits"
The first thing that comes to mind - wrong path. There is some missunderstanding between you and the task about what is the start point of your path. So try outputing the current_path in the rake task to see where is it loading and then just navigate from there.
My best guess would be that the rake task sets the path to the rails root path, but I might be wrong there.