Module import retarts server

Hi! There’s something I don’t understand about module imports. I thought I did, but apparently, I was wrong. Since Meteor 1.7, the imports directory is supposed to have become unnecessary when specifying explicit entry points for client and server. Here’s what I added to package.json:

"meteor": {
  "mainModule": {
    "client": "client/main.js",
    "server": "server/main.js"
  }
}

From what I understand, this setup would ensure that only files explicitely imported on the server would trigger a server restart, right? It works if I modify files that are nested in a client directory somewhere, but I just realized that modifying a file in any other directory, even though it is not used anywhere in server-side code, triggers a server restart.

Just as an example, if I create a new file at the root of the directory (which server should know nothing about), each time I modify it, the server restarts. Why is that?

1 Like

This was essentially a bug, that should be fixed in 1.8.2 I remember it coming up on the Meteor repo and Ben working on a fix.

There’s also the caveat that this only applies for js-like files. HTML and stylesheets will still get eagerly loaded with 'meteor.mainModule' set in package.json :eyes:

Do you mean that my understanding is correct, but that Meteor up to 1.8.2 is not loading files as expected?

Yes, your understanding of how it should work is correct.
Here’s the PR where it was fixed:

Great! Thanks a lot for your input. I’m glad to realize I do understand things correctly! :face_with_hand_over_mouth:

1 Like