Module Import error - cannot find module

12,488

Try

export default const jobs = {
  // your code
}

When you import, use

import { jobs } from './update-report-cron.js'
Share:
12,488
Shubham
Author by

Shubham

Updated on July 03, 2022

Comments

  • Shubham
    Shubham almost 2 years

    I was trying to import the module dynamically in ES6 on Meteor application. But getting an error cannot find module. The same import works when I'm using the static import statement.

    Please have a look at the below code -

    const JOBS = ['update-report-cron'];
    
    const jobs = {
      start() {
        JOBS.forEach((job) => {
          console.log(`job ${job} has been started`);
          let fileName = './' + job + '.js';
          console.log(require(fileName));
        })    
      } 
    };
    
    module.exports = {jobs};
    

    ERROR - Cannot find module './update-report-cron.js'