【问题标题】:Ruby on Rails [heroku] git push heroku master errorRuby on Rails [heroku] git push heroku master 错误
【发布时间】:2019-10-14 21:16:05
【问题描述】:

我正在尝试在 heroku 上上传我的网络应用程序,但出现以下错误。

(我正在使用 Cloud 9 IDE 进行编码)

$ git push heroku master
.....
remote: -----> Installing node-v10.14.1-linux-x64
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        Yarn executable was not detected in the system.
remote:        Download Yarn at https://yarnpkg.com/en/docs/install
remote:        I, [2019-05-22T02:13:47.373334 #1766]  INFO -- : Writing 
/tmp/build_fcc84922ee6a02bfc05a163c871d0548/public/assets/noimage- 
3aa3997354b4e9c37f379deb61626f55ade493078d1b42dcefe4a3ccbed34106.jpg
remote:        rake aborted!
remote:        ExecJS::RuntimeError: SyntaxError: Unexpected character '`'
remote:        JS_Parse_Error.get ((execjs):3538:621)
remote:        (execjs):4060:48
remote:        (execjs):1:102
.....
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.

首先,它说“系统中没有检测到Yarn可执行文件”,但是如果我用yarn -v检查它就可以正确下载。

另外,ExecJS :: RuntimeError: SyntaxError: Unexpected character '`' 错误好像是es6无法识别,作为解决办法

config.assets.js_compressor =: uglifier

config.assets.js_compressor = Uglifier.new(和谐:真)

改成这样好像可以读es6了。但上述错误仍然存​​在。

另外,如果我在控制台上运行“rake assets: precompile RAILS_ENV = production”,它会正常运行而不会出错。

谢谢。

【问题讨论】:

  • 你在检查heroku run yarn -v吗?
  • @maxpleaner 感谢您的评论。它显示 Running yarn -v on ⬢ myapp... up, run.1301(免费) bash: yarn: command not found。所以这意味着heroku上没有纱线?如何在 heroku 中下载纱线?

标签: ruby-on-rails ruby heroku ruby-on-rails-5


【解决方案1】:

尝试在你的 gem 文件中添加这个 gem。

gem 'therubyracer'

试试这个链接:

Syntax error when deploying Rails app to Heroku: ExecJS::RuntimeError: SyntaxError: Unexpected character

【讨论】:

    【解决方案2】:

    config.assets.js_compressor =: uglifier

    =: uglifier :uglifier 之间的空格?

    应该是= :uglifier

    并尝试使用不带字符串的预编译命令RAILS_ENV = production 因为 Heroku 默认安装生产模式。如果我没记错的话

    【讨论】:

      【解决方案3】:

      试试这个,转到他们网站上的 heroku 仪表板,选择您的应用程序,单击齿轮图标(设置),向下滚动直到看到“构建包”添加 ruby​​ 和 nodejs 构建包,然后确保 顺序是 nodejs 在列表中排在第一位,然后是 ruby​​(从上到下)。

      如果这不起作用,你能澄清一下你是如何触发你的 JS 编译的吗?

      说明:我以前见过这个错误(使用 npm,而不是 yarn),本质上你希望 herokus nodejs buildpack 负责 JS 编译,内置的一个 rails 似乎与他们的系统不兼容。

      【讨论】:

        猜你喜欢
        • 2016-02-19
        • 1970-01-01
        • 2013-02-03
        • 2016-12-26
        • 1970-01-01
        • 1970-01-01
        • 2014-07-05
        • 1970-01-01
        • 2011-05-23
        相关资源
        最近更新 更多