2017-09-05 40 views
2

我一直在试图通过Heroku,Nginx和Apache部署我的rails/browserify应用程序,并且我一直运行着同样的错误。当资产通过bundle exec rake assets:precompile db:migrate RAILS_ENV=production预编译时,我的一个JS类会产生语法错误。我在这里发现了一个类似的问题:ES6 Classes: Unexpected token in script? 但我的构造函数或方法之外没有任何变量声明。rails/browserify应用程序上的Javascript语法错误

错误:

rake aborted! 
 
ExecJS::RuntimeError: SyntaxError: Unexpected token: name (Game) 
 
JS_Parse_Error.get ((execjs):3538:621) 
 
(execjs):4060:47 
 
(execjs):1:102 
 
Object.<anonymous> ((execjs):1:120) 
 
Module._compile (module.js:571:32) 
 
Object.Module._extensions..js (module.js:580:10) 
 
Module.load (module.js:488:32) 
 
tryModuleLoad (module.js:447:12) 
 
Function.Module._load (module.js:439:3) 
 
Module.runMain (module.js:605:10)

所产生语法错误的JavaScript类:

class Game { 
 

 
    constructor(attributes) { 
 
     this.id = attributes.id; 
 
     this.characters = attributes.characters; 
 
     this.quotes = attributes.game_quotes; 
 
     this.state = attributes.state; 
 
     this.completed = attributes.completed; 
 
    } 
 

 
    score() { 
 
     if (this.completed == true) { 
 
      var score = 0; 
 
      for (var i = 0; i < this.state.length; i++) { 
 
       if (this.state[i] == true) { 
 
        score++; 
 
       } 
 
      } 
 
      return score; 
 
     } else { 
 
      return "Game Incomplete"; 
 
     } 
 
    } 
 

 
    percentageScore() { 
 
     if (this.score() >= 0) { 
 
      return (this.score() * 10 + "%"); 
 
     } else { 
 
      return "Game Incomplete"; 
 
     } 
 
    } 
 

 
    }

我在哪里语法错误?

这里是我的应用程序的存储库中的链接,如果你需要一些背景:Repository

来自社区的任何帮助将不胜感激。如果您能提供任何建议,请提前致谢。

回答

0

误差在config/environments/production.rb

config.assets.js_compressor = ...

注释掉以下行消失