Rake任务“assets:precompile”因JS编译问题失败

我正在尝试为 discourse 进行全新安装,并在运行 assets:precompile 任务时遇到以下错误。我看到了以下编译错误,但不确定错误是什么。

rake aborted!
Barber::PrecompilerError: Pre compilation failed for: {{#if isActive}}
  {{!-- template-lint-disable no-invalid-interactive --}}
  <div {{on "keydown" (action "keydown")}} class="emoji-picker {{if @isActive "opened"}}">
    {{!-- template-lint-enable no-invalid-interactive --}}
    <div class="emoji-picker-category-buttons">
      {{#if recentEmojis.length}}
        <button type="button" data-section="recent" {{action "onCategorySelection" "recent"}} class="btn btn-default category-button emoji">
          {{replace-emoji ":star:"}}
        </button>
      {{/if}}

      {{emoji-group-buttons onCategorySelection=(action "onCategorySelection") tagName=""}}

      {{#each-in customEmojis as |group emojis|}}
        <button type="button" data-section={{concat "custom-" group}} {{action "onCategorySelection" (concat "custom-" group)}} class="btn btn-default category-button emoji">
          {{replace-emoji (concat ":" emojis.firstObject.code ":")}}
        </button>
      {{/each-in}}
    </div>

    <div class="emoji-picker-content">
      <div class="emoji-picker-search-container">
        {{input
          class="filter"
          name="filter"
          placeholder=(i18n "emoji_picker.filter_placeholder")
          autocomplete="discourse"
          autocorrect="off"
          autocapitalize="off"
          input=(action "onFilter")
        }}

        {{d-icon "search"}}
      </div>

      <div class="emoji-picker-emoji-area" role="button" {{on "click" this.onEmojiSelection}} {{on "mouseover" this.onEmojiHover}}>
        <div class="results"></div>

        {{#conditional-loading-spinner condition=isLoading}}
          <div class="emojis-container">
            {{#if recentEmojis.length}}
              <div class="section recent" data-section="recent">
                <div class="section-header">
                  <span class="title">{{i18n "emoji_picker.recent"}}</span>
                  {{d-button icon="trash-alt" action=(action "onClearRecents") class="trash-recent"}}
                </div>
                <div class="section-group">
                  {{#each recentEmojis as |emoji|}}
                    {{replace-emoji (concat ":" emoji ":") (hash lazy=true)}}
                  {{/each}}
                </div>
              </div>
            {{/if}}

            {{emoji-group-sections}}

            {{#each-in customEmojis as |group emojis|}}
              <div class="section" data-section="custom-{{group}}">
                <div class="section-header">
                  <span class="title">
                    {{i18n (concat "emoji_picker." group)}}
                  </span>
                </div>
                {{#if emojis.length}}
                  <div class="section-group">
                    {{#each emojis as |emoji|}}
                      <img title={{emoji.code}} width="20" height="20" loading="lazy" class="emoji" src={{emoji.src}}>
                    {{/each}}
                  </div>
                {{/if}}
              </div>
            {{/each-in}}
          </div>
        {{/conditional-loading-spinner}}
      </div>

      <div class="emoji-picker-footer">
        <div class="emoji-picker-emoji-info">
          {{#if hoveredEmoji}}
            {{replace-emoji (concat ":" hoveredEmoji ":")}}
          {{/if}}
        </div>

        <div class="emoji-picker-diversity-picker">
          {{#each diversityScales as |diversityScale index|}}
            {{d-button
              icon=diversityScale.icon
              class=(concat "diversity-scale " diversityScale.name)
              title=diversityScale.title
              action=(action "onDiversitySelection" index)
            }}
          {{/each}}
        </div>
      </div>
    </div>
  </div>

  {{#if site.mobileView}}
    <div role="button" class="emoji-picker-modal-overlay" {{on "click" this.onClose}}></div>
  {{/if}}
{{/if}}

. Compiler said: Error
~/Discourse/Discourse-2.8.x/AL2_x86_64/DEV.STD.PTHREAD/build/private/env/ruby2.7.x/ruby2.7.x/lib/ruby/gems/2.7.0/gems/barber-0.12.2/lib/barber/precompiler.rb:33:in `rescue in compile'
~/Discourse/Discourse-2.8.x/AL2_x86_64/DEV.STD.PTHREAD/build/private/env/ruby2.7.x/ruby2.7.x/lib/ruby/gems/2.7.0/gems/barber-0.12.2/lib/barber/precompiler.rb:30:in `compile'
~/Discourse/Discourse-2.8.x/AL2_x86_64/DEV.STD.PTHREAD/build/private/env/ruby2.7.x/ruby2.7.x/lib/ruby/gems/2.7.0/gems/barber-0.12.2/lib/barber/precompiler.rb:8:in `compile'
~/Discourse/Discourse-2.8.x/AL2_x86_64/DEV.STD.PTHREAD/build/private/env/ruby2.7.x/ruby2.7.x/lib/ruby/gems/2.7.0/gems/ember-handlebars-template-0.8.0/lib/ember/handlebars/template.rb:166:in `block in precompile_ember_handlebars'
~/Discourse/Discourse-2.8.x/AL2_x86_64/DEV.STD.PTHREAD/build/private/env/ruby2.7.x/ruby2.7.x/lib/ruby/gems/2.7.0/gems/sprockets-3.7.2/lib/sprockets/cache.rb:85:in `fetch'
~/Discourse/Discourse-2.8.x/AL2_x86_64/DEV.STD.PTHREAD/build/private/env/ruby2.7.x/ruby2.7.x/lib/ruby/gems/2.7.0/gems/ember-handlebars-template-0.8.0/lib/ember/handlebars/template.rb:165:in `precompile_ember_handlebars'
~/Discourse/Discourse-2.8.x/AL2_x86_64/DEV.STD.PTHREAD/build/rails-root/lib/freedom_patches/raw_handlebars.rb:99:in `call'

这听起来不像标准安装?

2 个赞

是的,我正在尝试在一台 Amazon Linux 机器上进行自定义安装。

虽然 Discourse 是免费且开源的软件,但在此 Meta 上,我们将免费支持限制在遵循标准安装指南的安装上。由于运行该软件的方式有无数种组合,这使我们能够为所有用户提供易于使用且始终保持最新的基础。

如果您希望自定义 Discourse,无论是使用插件还是主题,您都可以在运行受支持的安装的同时更改一切。

2 个赞

而如果您通过分叉进行更改,您将非常后悔。

我已经找到了问题的根本原因。基本上,在运行 assets-precompile rake 任务时,它试图使用 [emoji-picker.hbs](https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/templates/components/emoji-picker.hbs) 中的 hbs 模板加载所有 js 文件。该模板包含某些变量,需要调用者提供数据,而这正是解析失败的地方。其他没有 @ 引用的 hbs 文件已成功编译。

关于 discourse 如何使用这些 hbs 模板,有什么想法或文档吗?

您可以从创建 Discourse 插件入门指南(第一部分:创建基础插件)开始。