[SOLVED] Meteor 1.3 not strictly enforcing import/export?

In Clock.jsx, I’m exporting this:

export default Clock = compose(onPropsChange)(Time);

And in another file, I’m referencing Clock:

import React from 'react';

export default class Home extends React.Component {
  render() {
    return <div>
      <Clock />
    </div>
  }
}

Notice there’s no import Clock from '../components/Clock.jsx', yet this still works without any errors or warnings. It seems like Meteor is not being strict about having to use export/import?

I always feel a sense of accomplishment when I answer my own questions. :wink:

From https://github.com/meteor/meteor/blob/release-1.3/packages/modules/README.md:

If you are familiar with modules in Node, you might expect modules not to be evaluated until the first time you import them. However, because earlier versions of Meteor evaluated all of your code when the application started, and we care about backwards compatibility, eager evaluation is still the default behavior.

If you would like a module to be evaluated lazily (in other words: on demand, the first time you import it, just like Node does it), then you should put that module in an imports/ directory (anywhere in your app, not just the root directory), and include that directory when you import the module: import {stuff} from “./imports/lazy”.

So, moving the definition of Clock into /client/imports/components made this work as expected.

4 Likes