1

I want to implement a async require so i am using a variable inside require keyword that is not working, But if i supply string it works as usual. I want a help to set it working properly

const asyncRequire = (path) => {
    try {
        return require(path);
    } catch (error) {
        LogUtils.error('Dynamic Require failed', error);
        return null;
    }
};

This require(path)is not working.

Tarik Sahni
  • 158
  • 1
  • 2
  • 13

1 Answers1

1

You cannot use dynamic paths in require currently. Please check this answer.

Check this issue also for discussions and possible alternatives.

Nishant Nair
  • 1,837
  • 13
  • 19