2

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.

5
  • whats the error? Commented Jun 6, 2019 at 11:39
  • 2
    remember, path must be relative to actually where you're calling require from, not asyncRequire Commented Jun 6, 2019 at 11:40
  • Yeah, it's relative but the require eywork is not taking varibale as an argument Commented Jun 6, 2019 at 11:52
  • Please use tags properly, tagging a question as both node.js and react reduces your chances of getting a proper solution for your environment Commented Jun 6, 2019 at 12:16
  • Possible duplicate of React Native - Image Require Module using Dynamic Names Commented Jun 6, 2019 at 12:59

1 Answer 1

2

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

Check this issue also for discussions and possible alternatives.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.