You can also use dynamic import. In your case, something like this:
if (Meteor.isServer) {
// Dynamically importing the fs module
import('fs').then(fsModule => {
const readdirSync = fsModule.default; // Accessing the default export
// Now you can use fs
}).catch(error => {
// Handle any errors that occurred during import
console.error("Failed to import 'moment':", error);
});
}
Maybe the syntax above is not 100% exact but check for dynamic import on ES6. There is also a synchronous dynamic import if needed if I remember correctly…