简体   繁体   中英

Meteor doesn't serve all HTML files in a directory

While working through Meteor TODO app tutorial, I ran into a problem at step 10, Publish and Subscribe .

The problem is that this code in imports/ui/task.js no longer works:

import { Meteor } from 'meteor/meteor'
import { Template } from 'meteor/templating';

import './task.html'; // <= fails in the browser

The directory imports/ui contains:

body.html   body.js     task.html   task.js

I can import './body.html'; fine, but not import './task.html'; , or any other HTML file for that matter -- eg I tried to rename task.html into flask.html and import it accordingly, and it still failed the same way.

Trying to debug it in Chrome I found that it sees a different set of files:

Chrome调试快照

Looking at this question I was able to find the generated app.js , which has

Template.body.addContent((function() {

but no (expected?)

Template.task.addContent

So my question is why Meteor build is not picking up task.html ?

NOTE: I have just updated Meteor to 1.8.0.2. Could that be a new bug in that release?

UPDATE

I restarted from scratch with the same tutorial and has made it through step 10 without problems.

I then ran a diff on the two projects. So far I was unable to find the root cause for this problem, however a cause was visible in

.meteor/local/build/programs/web.browser/app/app.js

as the attached diff shows: 新旧对比

The original (on the right) is missing the section generated from task.html

The question is still why? Are there any compile logs I can look at?

All right, @victor and @fred-stark were right on the money. It was a syntax error in the Blaze template!

<template name="task">
  <li class="{{#if checked}}checked{{/if}} {{#if private}}private{{/if}}">
    <button class="delete">&times;</button>

    <input type="checkbox" checked="{{checked}}" class="toggle-checked" />

    {{#if isOwner}}
      <button class="toggle-private">
        {{#if private}}
          Private
        {{#else}} // <= should be {{else}} !
          Public
        {{/if}}
      </button>
    {{/if}}
    <span class="text"><strong>{{username}}</strong> - {{text}}</span>
  </li>
</template>

I normally try to type it all myself when working on tutorials, instead of copy-paste. So, here I mistyped, subconsiously assuming the syntax for else would be the same as for if . Wrong!

Still it would be nice if there was some indication from the compiler during the build process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM