Rails Assets Precompile in production mode error - ruby-on-rails

When I run rake assets:prcompile RAILS_ENV=production, I am getting below error.But if i run in development mode it runs fine.
rake assets:precompile RAILS_ENV=production
rake aborted!
Uglifier::Error: fs redeclared
Environment
Rails 5.0.7
Ruby 2.4.1
Could someone helps to resolve this one

Got the issue.In my application.js file have below codes
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
As per functionality of require_tree, it will include current path's all js files recursively. Refer the link https://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives
In JavaScript files, Sprockets directives begin with //=. In the above case, the file is using the require and the require_tree directives. The require directive is used to tell Sprockets the files you wish to require. Here, you are requiring the files rails-ujs.js and turbolinks.js that are available somewhere in the search path for Sprockets. You need not supply the extensions explicitly. Sprockets assumes you are requiring a .js file when done from within a .js file.
The require_tree directive tells Sprockets to recursively include all JavaScript files in the specified directory into the output. These paths must be specified relative to the manifest file. You can also use the require_directory directive which includes all JavaScript files only in the directory specified, without recursion.
In my application , Gruntfile.js file was declared in two js folders.So, when I was doing the precompile,as the file was declared in two js , it throws error when it tried to compress that file

Related

Rails Asset Pipeline not compiling assets

In my application.js file, I have the following:
//= require jquery
//= require vendor
When I load up a Rails server with rails s the application.js file that is served still has the require statements at the top. I expect it to remove these lines and load the jquery file separately.
I'm using Rails 3.2.19. My RAILS_ENV is not set.
Though I'm not entirely sure that what you're doing doesn't work, I typically use //= require [name of js file]. e.g. //= require bootstrap.js when bootstrap.js is inside the vendors/javascript folder.
Are you using an old version of Ruby? Maybe something from before 1.9.3? I had similar before problems when upgrading Rails without upgrading Ruby.
Bug with sprockets 2.2.1
Updated to sprockets 2.2.2 (via bundle update sprockets) and it now works

Sprockets require all files from a gem's folder

So I'm using the jqPlot gem in Rails, and in order to use plugins, I'm required to do a
//=require jqplot/plugins/plugin-name
for each plugin that I want to use. Given that there are currently ~30 plugins in jqPlot, as I use more and more plugins, my application.js manifest will get bloated up with all the plugin requires. As a result, I was wondering if there was a way to require the entire plugin folder with a single require, as that would be significantly cleaner.
I've tried //=require_tree ./jqplot/plugins and //= require_tree ./jqplot/plugins/, and replacing require_tree with require_directory and all I get is an ArgumentError that require_tree/require_directory argument must be a directory.

Javascript files are not included from manifest

I am using Ruby On Rails and have ActiveAdmin on top of that on a windows machine. I donĀ“t think ActiveAdmin has anything to do with it, but I am just saying.
The Javascript file that is included via HTML is /assets/active_admin.js and the manifest file itself looks like this:
//= require active_admin/base
//= require just_datetime_picker/nested_form_workaround
When I run my Rails application and open http://localhost:3000/assets/active_admin.js, the log tells me, that active_admin.js was compiled, but the file still looks just like the manifest just with an added semicolon at the end:
//= require active_admin/base
//= require just_datetime_picker/nested_form_workaround
;
Why is no Javascript code included?
When I try to run the precompile pipeline manually via bundle exec rake assets:precompile RAILS_ENV=development, it actually creates all the CSS files, but the JS files still look like the one described above.
Since I am operating on a windows machine, I do not have the gem 'therubyracer' installed, but NodeJS. Also the bundle install works fine and I also do not get any errors.
Are you using Ruby v2.0? Try downgrading to 1.9.
Symptom: The JavaScript manifest file does not compile, no errors are shown; however, a mysterious semi-colon ; appears at the end of the file after "preprocessing" the assets.
Solution: Downgrade to Ruby v1.9.3!
See two other posts on the same topic.
My Rails Javascript manifest file neither compiles nor include any required files
Javascript manifest file "application.js" is not processed
What a sorry mess it is to be programming in 2013!

Rails asset pipeline require

In rails to require a file in the vendor directory I know that I can do this in my application.j file.
//=require vendor/assets/javascripts/me.js
Am wondering how does one require the entire javascript folder in the vendor directory
//= require_tree ../../../vendor/assets/javascripts/include/.
See http://guides.rubyonrails.org/asset_pipeline.html#asset-organization
Try
//=require me
Vendor should be loaded by default
Assets are not namespaced
You might need to restart your dev server after adding to vendor

Rails and codekit - how to disable rails coffescript compilation

I'm using rails 3.2, but I'm compiling my coffee files with CodeKit.
I still want my coffee files to live inside 'assets', but each time I restart rails, it finds them in there and tries to compile them itself.
My files live in /assets/cafe/myscript.coffee, and codekit compiles them into /assets/javascripts/myscript.js
The coffee-rails gem is already commented out in my gemfile (when rails tries to (re) compile it it gives "throw Error("LoadError: no such file to load -- coffee_script)" - though I really dont want it to even try compiling.
Setting "config.assets.compile = false" in application.rb results in "application.js isn't precompiled"
you should probably just configure your sprockets manifest to not require the whole tree.
edit app/assets/javascripts/application.js
typically it looks like this:
//= require jquery
//= require jquery_ujs
//= require_tree .
change that to
//= require jquery
//= require jquery_ujs
//= require myscript
An (inferior) workaround is to put my coffeescripts inside "App" rather than "assets" (so one more branch up the tree.)
This sucks because it's not where they should go, but at least it does put it outside rails' stalker-tendencies to find coffeescript files anywhere in assets and try to compile them.

Resources