Precompiling assets failed ExecJS::ProgramError: Unexpected token: operator (=) (line: 10770 , col: 0, pos: 300859)

前端 未结 5 1911
傲寒
傲寒 2020-12-30 06:46

I am having issues pushing my rails project to heroku. I get a \"Precompiling assets failed\" message . I am new to programming and new to ruby on rails. I really need some

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-30 07:16

    You probably already solved this by now, but I stumbled across this issue and wanted to share my solution.

    As an answer above suggested, the best way to track the error down to the problematic file is to run

    rake assets:precompile RAILS_ENV=production

    locally while excluding files or directories you might think contain the problem. I deleted directories one by one (which I could later checkout again from my repo) until I got the precompilation running. I then drilled down into the last deleted directory and tracked it down to a certain file and a function of the form

    array.find(name => name.id === user_id);
    

    My research showed that it turns out the largest update to Javascript (ES5) was released in 2009 and since then, only unitl June 2015 was the ECMAScript 6 (ES6) final specification released. The syntax used in this function is supported by ES6 but not ES5 and ES6 is not yet supported on Rails (I was running RoR 5.0.0.1), at least not with ExecJS on the assets pipeline.

    What you CAN do, is change your function to an alternative syntax, namely

    array.find(function(name){return name.id === user_id});
    

    and it should work equivalently.

    • More on the find function here
    • To get ES6 working on RoR, you might want to check out Babel, as described here

提交回复
热议问题