Module Import error - cannot find module
Asked Answered
L

2

7

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'

Lustick answered 23/2, 2018 at 9:49 Comment(0)
P
2

Try

export default const jobs = {
  // your code
}

When you import, use

import { jobs } from './update-report-cron.js'
Payroll answered 23/2, 2018 at 10:27 Comment(0)
A
2

Ru's answer is not correct, not sure how it's your answer.

Try

export default const jobs = {
  // your code
}

When you import, use

import jobs from './update-report-cron.js'
Aldwon answered 23/11, 2022 at 18:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.