title: React + Webpack: Dynamic Image Cannot find module 'assets/images/logo.jpg' t |groupOptions: {}|namespace object:87:1
body: <p>I am trying to develop a Header that it takes logo image dynamically depends the client.</p>
  <p>I have a JSON that stores the information, for example</p>
  <pre><code>{
      &quot;clientLogo&quot;: &quot;assets/images/cLogo.jpg&quot;,
         ...
  }
  </code></pre>
  <p>and I store it at a ContextProvider.</p>
  <p>An example of code at my component:</p>
  <pre><code>const Header = () =&gt; {
  const { clientLogo, clientName } = useClientContext();
  const [clientLogoImage, setClientLogoImage] = useState(null);
  
  useEffect(() =&gt; {
      if (clientLogo) {
          import(clientLogo)
              .then((clientLogoImg) =&gt; {
                  setClientLogoImage(clientLogoImg);
              })
              .catch((err) =&gt; console.error(err));
      }
  }, [clientLogo]);
  
  return (
      &lt;StyledHeader className=&quot;header&quot;&gt;
          &lt;div className=&quot;header-container&quot;&gt;
              {clientLogoImage &amp;&amp; (
                  &lt;img
                      loading=&quot;lazy&quot;
                      src={clientLogoImage}
                      className=&quot;logo&quot;
                      alt={clientName}
                  /&gt;
              )}
          &lt;/div&gt;
         ....
  </code></pre>
  <p>I have already ensured that <code>clientLogo = &quot;assets/images/cLogo.jpg&quot;</code> and if I execute</p>
  <pre><code>useEffect(() =&gt; {
      if (clientLogo) {
          import(&quot;assets/images/cLogo.jpg&quot;)
              .then((clientLogoImg) =&gt; {
                  setClientLogoImage(clientLogoImg);
              })
              .catch((err) =&gt; console.error(err));
      }
  }, [clientLogo]);
  </code></pre>
  <p>It works.</p>
  <p>The problem is that when I use clientLogo variable I have this problem</p>
  <pre><code>Header.js:15 Error: Cannot find module 'assets/images/cLogo.jpg'
      at |groupOptions: {}|namespace object:87:1
  </code></pre>
  <p>DO you have any idea?
  Thank you in advance!</p>