Error when running `rake assets:precompile`

12,821

Solution 1

Take a look at this url this is almost same error. https://github.com/resolve/refinerycms/issues/1186

Fix is here : https://github.com/resolve/refinerycms/pull/1189

Summary: Your are missing 'comma' sign or 'semicolon' sign somewhere in your application.js file. Log full trace here while running locally by following command:

bundle exec rake assets:precompile --trace

Solution 2

My suggestion. Remove the require_tree line. That tends to be overkill and creates way more problems. It's much better to specifically require files as opposed to adding everything in a directory.

http://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives

Explanation.

You have a misplaced comma. or semicolon. It's very unlikely that it's in jquery or jquery_ujs, it's probably in another file, but the notable line is the require_tree line:

//= require jquery
//= require jquery_ujs
//= require_tree

Looking in your question, you mentioned that "However this application.js file only contains some comments." Those aren't comments! Those are actually requiring those files and including them in. The magic of Rails, and in this case Sprockets, is that you can write a javascript file, and add requires at the top, which will include all those files at the top. This way, you can include vendor libraries like jQuery, but then you only have to work with one javascript file.

So those comments above are including jquery, the rails jquery helper libraries and then the require_tree includes every other file inside the javascripts directory. Open your website up on your local machine and look at the source. I bet you have some additional javascript files you weren't expecting.

Share:
12,821
Vasseurth
Author by

Vasseurth

SOreadytohelp

Updated on June 04, 2022

Comments

  • Vasseurth
    Vasseurth almost 2 years

    I have a rails 3.1 app that I am trying to push to heroku. While the push works, the error lies when it tries to rake the assets. It get an error

    Unexpected token punc, expected punc (line: 11225, col: 7, pos: 321149)
    undefined
    (in /Users/Matt/Orchive/Orchive/app/assets/javascripts/application.js)
    

    However this application.js file only contains some comments. Here it is:

    // This is a manifest file that'll be compiled into including all the files listed below.
    // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
    // be included in the compiled file accessible from http://example.com/assets/application.js
    // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
    // the compiled file.
    //
    //= require jquery
    //= require jquery_ujs
    //= require_tree
    

    I don't really understands assets but I tried running rake assets:precompile in the terminal before pushing and got this large error

    /Users/Matt/.rvm/rubies/ruby-1.9.2-p180/bin/ruby /Users/Matt/.rvm/gems/ruby-1.9.2-p180/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
    rake aborted!
    Unexpected token punc, expected punc (line: 11225, col: 7, pos: 321149)
    
    undefined
    (in /Users/Matt/Orchive/Orchive/app/assets/javascripts/application.js)
    
    Tasks: TOP => assets:precompile:primary
    (See full trace by running task with --trace)
    rake aborted!
    Command failed with status (1): [/Users/Matt/.rvm/rubies/ruby-1.9.2-p180/bi...]
    
    Tasks: TOP => assets:precompile
    (See full trace by running task with --trace)
    

    I can edit this and change that to what it shows with --trace if that would be more helpful. I think that this is a common, easy fix error that I just don't know how to do.