<p dir="auto">From the docs on static HTML export:</p>
<blockquote>
<p dir="auto">So, you could only use pathname, query and asPath fields of the context object passed to getInitialProps. You can't use req or res fields.</p>
</blockquote>
<p dir="auto">Does static export entirely negate the ability to use the _error.js component for error handling, which is dependent on <code class="notranslate">res</code>? How would I go about creating a 404 page?</p>
<p dir="auto">The current behavior is that any unknown routes redirect to <code class="notranslate">/index.js</code>.</p>
<p dir="auto">One possible solution I can think of is to maintain a list of all routes and check against it to see if pathname is found. However this seems especially onerous to run on every page load for a site/blog that generates 100s of routes.</p>
<p dir="auto">Is there a way to do this?<br>
Or is it possible to define a custom error route and redirect to that instead?<br>
Or even better, catch all routes within subfolders? eg</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" {
    ...routes,
     '/*': { page: '/_error.js' },
    '/blog/*': { page: '/blog/_error.js' },
  }"><pre class="notranslate"><code class="notranslate"> {
    ...routes,
     '/*': { page: '/_error.js' },
    '/blog/*': { page: '/blog/_error.js' },
  }
</code></pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/zeit/next.js/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h1 dir="auto">Bug report</h1>
<h2 dir="auto">Describe the bug</h2>
<p dir="auto">Building nextjs app throws an error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Failed to compile.

chunk c8f7fe3b0e41be846d5687592cf2018ff6e22687
static/css/030f3c81fcf6deab04e9.css
Cannot read property 'pop' of undefined"><pre class="notranslate"><code class="notranslate">Failed to compile.

chunk c8f7fe3b0e41be846d5687592cf2018ff6e22687
static/css/030f3c81fcf6deab04e9.css
Cannot read property 'pop' of undefined
</code></pre></div>
<h2 dir="auto">To Reproduce</h2>
<p dir="auto">add some [name].module.css and build the app</p>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto">App builds without errors</p>
<h2 dir="auto">Screenshots</h2>
<p dir="auto">If applicable, add screenshots to help explain your problem.</p>
<h2 dir="auto">System information</h2>
<ul dir="auto">
<li>OS: Tried on MacOS (nodejs v10 and nodejs v12) and Linux (Docker container node:12)</li>
<li>Version of Next.js: 9.0.2</li>
</ul>
<h2 dir="auto">Additional context</h2>
<p dir="auto">adding next snippet in my next.config.js solves the issue but I don't think it is the best way</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    if (config.optimization.splitChunks) {
      config.optimization.splitChunks.cacheGroups.shared.enforce = true;
    }"><pre class="notranslate"><code class="notranslate">    if (config.optimization.splitChunks) {
      config.optimization.splitChunks.cacheGroups.shared.enforce = true;
    }
</code></pre></div>