3

I've created a JavaScript class (named as BarChart) that have constructor and several methods init.

I executed below command to pre-compile assets for production environment but got error.

Command used to pre-compiling assets: rake assets:precompile RAILS_GROUPS=assets --trace

Error backtrace:

rake aborted!
ExecJS::ProgramError: SyntaxError: Unexpected token: name (BarChart) (line: 24472, col: 6, pos: 952834)

Error
    at new JS_Parse_Error (<eval>:3623:11948)
    at js_error (<eval>:3623:12167)
    at croak (<eval>:3623:22038)
    at token_error (<eval>:3623:22175)
    at unexpected (<eval>:3623:22263)
    at semicolon (<eval>:3623:22781)
    at simple_statement (<eval>:3623:25959)
    at <eval>:3623:23747
    at <eval>:3623:22954
    at <eval>:3624:3759
    at Object.parse (<eval>:3624:3999)
    at parse (<eval>:3958:22)

Javascript class which throws error is written like:

class BarChart
{
    // code goes here
}

I've added therubyracer and execjs gem in Gemfile.

Ruby: 2.2.5

Rails: 3.2.2`

PS: I've checked several questions of this type in SO, but none of the issue is related to JavaScript class.

Radix
  • 2,527
  • 1
  • 19
  • 43
  • Seems like there're two requests to close question. Can someone please explain me the reason of the **close** question request? I didn't found JS class related issue yet. – Radix Feb 20 '17 at 13:33
  • 1
    I voted to close it because I do not understand it - it is unclear to me. Imagine yourself on the place of someone who has no slightest clue of your problem and describe it in a way one could understand it. The better (do not confuse with "the more") you describe the issue, the higher chances to get proper answer. – Andrey Deineko Feb 20 '17 at 13:49
  • Check this link. Hope this will help you. http://www.academytimes.com/solved/7392211522/rails-5-heorku-deploy-error-execjsprogramerror-syntaxerror-unexpected-token – Code Lღver Feb 20 '17 at 13:55
  • @CodeLღver Thanks for your answer but I've already checked that and it does not solve my error. – Radix Feb 20 '17 at 13:57
  • @AndreyDeineko I've updated the question, please check. BTW, thanks for providing the reason for closing the question. – Radix Feb 20 '17 at 13:58

3 Answers3

1

In your BarChart js file, change all the let to var. Then the precompile should go successfully.

Liren Yeo
  • 3,215
  • 2
  • 20
  • 41
1

I'd written the JavaScript in ES6 and rails 3 shows error while ES6 code. All the methods of using ES6 in rails is not for rails 3. So I converted ES6 to ES5 code.

Radix
  • 2,527
  • 1
  • 19
  • 43
1

In rails 5 I resolved the issue renaming files from .js to .js.es6. Weirdly it my staging deploy worked and my production deploy did not.

Marcelo
  • 1,702
  • 2
  • 24
  • 42