1

I'm running RAILS_ENV=production bundle exec rake assets:precompile and getting this error

...somefile.js
ExecJS::ProgramError: Unexpected token: operator (-) (line: 3, col: 9, pos: 11)

This is the content of that line:

var color-green="#27cebc";

I guess the problem is because the variable name includes a -. However using the same ruby version on local computer with same command, it's able to process correctly without the error:

On my local computer:

RAILS_ENV=production bundle exec rake assets:precompile`

And it was able to process the offending file without problems, and generated this file:

public/assets/js/some=file-68c9a5f2e1f2216c5d3d2b9fcd7741155113425f7f46f18187ad5b98e1a11092.js

$ ruby -v
ruby 2.2.1p85
$ gem list | grep js
execjs (2.5.2)

I tried commenting the line out and it process all the files succesfully, but I dont understand why on local it works with that line, and in the server doesnt.

Arnold Roa
  • 7,335
  • 5
  • 50
  • 69

2 Answers2

0

The only reason is assets not compile in development mode. but when you start in production mode its need to compile first.

you can see difference between development.rb and production.rb in environment folder.

you can explore more here.

config.assets.compile=true in Rails production, why not?

Community
  • 1
  • 1
Hardik Upadhyay
  • 2,639
  • 1
  • 19
  • 34
  • I ran this on local `RAILS_ENV=production bundle exec rake assets:precompile` and it were able to process all assets including the offending one, is the same command ran on the server – Arnold Roa Jul 09 '16 at 11:18
  • you mean to say you run command on local and its execute without error but its throw error with same code on server. – Hardik Upadhyay Jul 09 '16 at 11:37
0

You were able to use it locally because you weren't doing the precompilation/preprocessing locally.

However, I doubt if it really worked locally as JS would have thrown an exception of Unexpected token -, because the interpretation of the line is color minus green, as you cannot use - in the name of a variable

oreoluwa
  • 5,553
  • 2
  • 20
  • 27
  • I ran this on local `RAILS_ENV=production bundle exec rake assets:precompile` and it were able to process all assets including the offending one, is the same command ran on the server – Arnold Roa Jul 09 '16 at 11:18