Google News
logo
Meteor.js - Interview Questions
How to Using 'require' In Meteor?
In Meteor, import statements compile to CommonJS require syntax. However, as a convention we encourage you to use import.
 
With that said, in some situations you may need to call out to require directly. One notable example is when requiring client or server-only code from a common file. As imports must be at the top-level scope, you may not place them within an  if  statement, so you’ll need to write code like:
if (Meteor.isClient) {
  require('./client-only-file.js');
}
Note that dynamic calls to require() (where the name being required can change at runtime) cannot be analyzed correctly and may result in broken client bundles.
 
If you need to require from an ES2015 module with a default export, you can grab the export with require("package").default.
Advertisement