admin管理员组

文章数量:1287774

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'

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'

Share Improve this question asked Feb 23, 2018 at 9:49 ShubhamShubham 1,2012 gold badges17 silver badges39 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

Try

export default const jobs = {
  // your code
}

When you import, use

import { jobs } from './update-report-cron.js'

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'

本文标签: javascriptModule Import errorcannot find moduleStack Overflow