title: Module not found when run build webpack with ejs module
body: <p>I have a simple project where I use the ejs module and webpack without a lot of configuration.<br />
  When I run the index.js with node everything is fine.<br />
  When I try to run build I get following error message:</p>
  <p><strong>Error Message:</strong></p>
  <pre><code>        PS C:\Users\Florian\Desktop\template_ejs_webpack&gt; npm run build-prod
      
      &gt; template_mit_ejs@1.0.0 build-prod C:\Users\Florian\Desktop\template_ejs_webpack
      &gt; webpack --mode production
      
      assets by status 10.1 KiB [cached] 1 asset
      modules by path ./node_modules/ejs/lib/*.js 30.1 KiB
        ./node_modules/ejs/lib/ejs.js 26.1 KiB [built] [code generated]
        ./node_modules/ejs/lib/utils.js 4.07 KiB [built] [code generated]
      ./src/index.js 301 bytes [built] [code generated]
      ./node_modules/ejs/package.json 1.47 KiB [built] [code generated]
      
      ERROR in ./node_modules/ejs/lib/ejs.js 47:9-22
      Module not found: Error: Can't resolve 'fs' in 'C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\ejs\lib'
      resolve 'fs' in 'C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\ejs\lib'
        Parsed request is a module
        using description file: C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\ejs\package.json (relative path: ./lib)
          Field 'browser' doesn't contain a valid alias configuration
          resolve as module
            C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\ejs\lib\node_modules doesn't exist or is not a directory
            C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\ejs\node_modules doesn't exist or is not a directory
            C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\node_modules doesn't exist or is not a directory
            looking for modules in C:\Users\Florian\Desktop\template_ejs_webpack\node_modules
              single file module
                using description file: C:\Users\Florian\Desktop\template_ejs_webpack\package.json (relative path: ./node_modules/fs)
                  no extension
                    Field 'browser' doesn't contain a valid alias configuration
                    C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\fs doesn't exist
                  .js
                    Field 'browser' doesn't contain a valid alias configuration
                    C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\fs.js doesn't exist
                  .json
                    Field 'browser' doesn't contain a valid alias configuration
                    C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\fs.json doesn't exist
                  .wasm
                    Field 'browser' doesn't contain a valid alias configuration
                    C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\fs.wasm doesn't exist
              C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\fs doesn't exist
            C:\Users\Florian\Desktop\node_modules doesn't exist or is not a directory
            C:\Users\Florian\node_modules doesn't exist or is not a directory
            C:\Users\node_modules doesn't exist or is not a directory
            C:\node_modules doesn't exist or is not a directory
       @ ./src/index.js 4:12-26
      
      ERROR in ./node_modules/ejs/lib/ejs.js 48:11-26
      Module not found: Error: Can't resolve 'path' in 'C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\ejs\lib'
      
      BREAKING CHANGE: webpack &lt; 5 used to include polyfills for node.js core modules by default.
      This is no longer the case. Verify if you need this module and configure a polyfill for it.
      
      If you want to include a polyfill, you need to:
              - add a fallback 'resolve.fallback: { &quot;path&quot;: require.resolve(&quot;path-browserify&quot;) }'
              - install 'path-browserify'
      If you don't want to include a polyfill, you can use an empty module like this:
              resolve.fallback: { &quot;path&quot;: false }
      resolve 'path' in 'C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\ejs\lib'
        Parsed request is a module
        using description file: C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\ejs\package.json (relative path: ./lib)
          Field 'browser' doesn't contain a valid alias configuration
          resolve as module
            C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\ejs\lib\node_modules doesn't exist or is not a directory
            C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\ejs\node_modules doesn't exist or is not a directory
            C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\node_modules doesn't exist or is not a directory
            looking for modules in C:\Users\Florian\Desktop\template_ejs_webpack\node_modules
              single file module
                using description file: C:\Users\Florian\Desktop\template_ejs_webpack\package.json (relative path: ./node_modules/path)
                  no extension
                    Field 'browser' doesn't contain a valid alias configuration
                    C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\path doesn't exist
                  .js
                    Field 'browser' doesn't contain a valid alias configuration
                    C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\path.js doesn't exist
                  .json
                    Field 'browser' doesn't contain a valid alias configuration
                    C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\path.json doesn't exist
                  .wasm
                    Field 'browser' doesn't contain a valid alias configuration
                    C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\path.wasm doesn't exist
              C:\Users\Florian\Desktop\template_ejs_webpack\node_modules\path doesn't exist
            C:\Users\Florian\Desktop\node_modules doesn't exist or is not a directory
            C:\Users\Florian\node_modules doesn't exist or is not a directory
            C:\Users\node_modules doesn't exist or is not a directory
            C:\node_modules doesn't exist or is not a directory
       @ ./src/index.js 4:12-26
      
      webpack 5.24.1 compiled with 2 errors in 906 ms
      npm ERR! code ELIFECYCLE
      npm ERR! errno 1
      npm ERR! template_mit_ejs@1.0.0 build-prod: `webpack --mode production`
      npm ERR! Exit status 1
      npm ERR!
      npm ERR! Failed at the template_mit_ejs@1.0.0 build-prod script.
      npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
      
      npm ERR! A complete log of this run can be found in:
      npm ERR!     C:\Users\Florian\AppData\Roaming\npm-cache\_logs\2021-02-24T13_35_40_240Z-debug.log
  </code></pre>
  <p><strong>Folder Structure:</strong></p>
  <pre><code>
      template_ejs_webpack
      |--dist
      |  |--index.html
      |--node_modules
      |--src
      |  |--index.js
      |--package-lock.json
      |--package.json
      |--template.ejs
      |--webpack.config.js
  
  </code></pre>
  <p><strong>index.js:</strong></p>
  <pre><code>
      &quot;use strict&quot;
      
      
      const ejs = require(&quot;ejs&quot;)
      
      const planet = &quot;Mars&quot;
      
      ejs
          .renderFile(&quot;./template.ejs&quot;, { planetVar: planet })
          .then((templateHTML) =&gt; {
              console.log(templateHTML)
          })
  
  </code></pre>
  <p><strong>index.html:</strong></p>
  <pre><code>
      &lt;!DOCTYPE html&gt;
      &lt;html lang=&quot;en&quot;&gt;
      &lt;head&gt;
          &lt;meta charset=&quot;UTF-8&quot;&gt;
          &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
          &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
          &lt;title&gt;Document&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div id=&quot;output&quot;&gt;&lt;/div&gt;
      
          &lt;script src=&quot;./main.js&quot;&gt;&lt;/script&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  
  </code></pre>
  <p><strong>template.ejs:</strong></p>
  <pre><code>
      &lt;p&gt;Mission accomplished. Landed on &lt;%= planetVar %&gt;&lt;/p&gt;
  
  </code></pre>
  <p><strong>package.json:</strong></p>
  <pre><code>
      {
          &quot;name&quot;: &quot;template_mit_ejs&quot;,
          &quot;version&quot;: &quot;1.0.0&quot;,
          &quot;description&quot;: &quot;&quot;,
          &quot;main&quot;: &quot;script.js&quot;,
          &quot;scripts&quot;: {
              &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;,
              &quot;build&quot;: &quot;webpack&quot;,
              &quot;build-prod&quot;: &quot;webpack --mode production&quot;,
              &quot;watch&quot;: &quot;webpack --watch&quot;
          },
          &quot;author&quot;: &quot;&quot;,
          &quot;license&quot;: &quot;ISC&quot;,
          &quot;dependencies&quot;: {},
          &quot;devDependencies&quot;: {
              &quot;ejs&quot;: &quot;^3.1.6&quot;,
              &quot;ejs-loader&quot;: &quot;^0.5.0&quot;,
              &quot;webpack&quot;: &quot;^5.24.1&quot;,
              &quot;webpack-cli&quot;: &quot;^4.5.0&quot;
          }
      }
  
  </code></pre>
  <p><strong>webpack.config.js:</strong></p>
  <pre><code>
      module.exports = {
          mode: 'development',
          target: 'web',
          module: {
              rules: [
                  {
                      test: /\.ejs$/,
                      use: {
                          loader: 'ejs-loader'
                      }
                  }
              ]
          }
        };
  
  </code></pre>
  <p>Does anyone have a suggestion what is wrong with my code?</p>