G
G
GreaterGlider2019-12-20 18:26:56
React
GreaterGlider, 2019-12-20 18:26:56

Why is the module not loading when using require?

Good day to all.
I'm trying to figure out why this code might not work:

useEffect(() => {
    setPagesList(config.pages.map(page => {
      return require(`${page.path}`);
    }));
  }, []);

, where page is an object of the form {path: '../../data/data2.md', title: "Chapter 2"},
Moreover, if I pass the string: Then everything works fine. Same effect when using dynamic imports. Error text: Error: Cannot find module '../../data/data2.md'
return require('../../data/data2.md',);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question