Fabian Bosler
Fabian Bosler

Reputation: 2510

Why do I not have to import { Meteor } from 'meteor/meteor' and can still use it and should I?

So I have noticed that I can use Meteor methods anywhere in my project even without importing it explicitly.

My question now is twofold:

  1. Why does this work?
  2. Should I use it without importing? (what are the possible risks of doing so?)

Upvotes: 1

Views: 640

Answers (1)

mparkitny
mparkitny

Reputation: 1195

When 1.3 version was released, the biggest new feature was ES6 modules.

import { Meteor } from 'meteor/meteor'
import { EJSON } from 'meteor/ejson'

Although you can use this feature(and you should), Meteor is still backwards compatible and bind some packages to the global variable. This is the reason why it works for you at the moment. You should NOT use it without importing. The main risk are future updates. At some point, the new version of Meteor won't be compatible with older applications. If you won't have imported packages, you will need to do some unnecessary extra work. Otherwise, your application won't work.

If you want to read more about this topic I found some interesting links:

Upvotes: 4

Related Questions