I\'m trying to precompile my assets for production, but rails doesn\'t seem to be cooperating.
$ bundle exec rake assets:precompile
/home/drderp/.rvm/rubies/
For us, it was a weird little thing which leads us to actual underlying error, hence solution.
We had uglifier gem v 4.1.x
and latest at the time of writing is 4.2.x
we updated the uglifier version, just in case.
And what happened was that this new version actually started spitting out actual file locations where the error of compilation was happening. And when we know where the error is coming from, we fix it.
The actual issue was that we had some js.erb
files and these files were running some rails code to populate some env data, something like:
const config = {
abc: <%= Figaro.env.abc %>,
xyz: <%= Figaro.env.xyz %>
}
And the error we were getting was: Uglifier::Error: Unexpected token: punc (,)
.
So it was obvious for some reason Figaro was not giving us our desired values. We went on to fix that and checked our assumption by hardcoding random values, which compiled the JS successfully.
Putting it here so it may help someone.
PS: Top answer is great, but for some reason, it gave us some random jsx related errors to us instead of giving us an actual error.