<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>
<p dir="auto">Next5 causes some subtle breakage when developing in code that worked correctly in Next4, for a site that uses express. In particular, two things are observed in dev mode:</p>
<ol dir="auto">
<li>There is a flash of unstyled site before all <code class="notranslate">&lt;styled jsx&gt;</code> CSS loads on first load. (Client side navs are still fine.)</li>
<li>401s on HMR, when using express-basic-auth.</li>
</ol>
<h2 dir="auto">Steps to Reproduce (for bugs)</h2>
<p dir="auto">I created a minimal folder structure to demo the second behaviour: <a href="https://www.dropbox.com/s/ulazf3kutnsve2v/simple.tgz?dl=0" rel="nofollow">https://www.dropbox.com/s/ulazf3kutnsve2v/simple.tgz?dl=0</a></p>
<ol dir="auto">
<li>Unzip, run yarn install, yarn dev (this uses Next 4.2.3.)</li>
<li>Visit localhost:3000, enter "something", "secure"</li>
<li>Open console.</li>
<li>Edit index.js</li>
<li>In the Network tab, observe that <code class="notranslate">on-demand-entries-ping?page=/</code> returns a 200.</li>
<li>Stop the server</li>
<li>yarn add next@latest, yarn dev.</li>
<li>Visit localhost:3000, enter "something", "secure" (new incognito window if you like)</li>
<li>Edit index.js</li>
<li>In the Network tab, observe that <code class="notranslate">on-demand-entries-ping?page=/</code> returns a 401.</li>
</ol>
<h1 dir="auto">Bug report</h1>
<h2 dir="auto">Describe the bug</h2>
<p dir="auto">In the case using <code class="notranslate">target: 'serverless'</code> flag in <code class="notranslate">next.config.js</code>, the <a href="https://github.com/zeit/next.js/tree/canary/examples/with-ant-design-less">with-ant-design-less</a> sample code build failed.</p>
<div class="highlight highlight-text-shell-session notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ yarn build
yarn run v1.17.3
$ next build
Creating an optimized production build ...

&gt; Using external babel configuration
&gt; Location: &quot;/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.babelrc&quot;
Compiled with warnings.

./node_modules/component-classes/index.js
Module not found: Can't resolve 'indexof' in '/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/node_modules/component-classes'

&gt; Build error occurred
TypeError: (0 , _styleChecker.default) is not a function
    at Object.g5iu (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:37583:55)
    at __webpack_require__ (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:23:31)
    at Object.3PeW (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:3977:36)
    at __webpack_require__ (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:23:31)
    at Object.lbd2 (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:42120:36)
    at __webpack_require__ (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:23:31)
    at Module.ILaR (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:15153:18)
    at __webpack_require__ (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:23:31)
    at /Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:91:18
    at Object.&lt;anonymous&gt; (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:94:10)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
"><pre class="notranslate">$ <span class="pl-s1">yarn build</span>
<span class="pl-c1">yarn run v1.17.3</span>
$ <span class="pl-s1">next build</span>
<span class="pl-c1">Creating an optimized production build ...</span>

&gt; <span class="pl-s1">Using external babel configuration</span>
&gt; <span class="pl-s1">Location: <span class="pl-s"><span class="pl-pds">"</span>/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.babelrc<span class="pl-pds">"</span></span></span>
<span class="pl-c1">Compiled with warnings.</span>

<span class="pl-c1">./node_modules/component-classes/index.js</span>
<span class="pl-c1">Module not found: Can't resolve 'indexof' in '/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/node_modules/component-classes'</span>

&gt; <span class="pl-s1">Build error occurred</span>
<span class="pl-c1">TypeError: (0 , _styleChecker.default) is not a function</span>
<span class="pl-c1">    at Object.g5iu (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:37583:55)</span>
<span class="pl-c1">    at __webpack_require__ (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:23:31)</span>
<span class="pl-c1">    at Object.3PeW (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:3977:36)</span>
<span class="pl-c1">    at __webpack_require__ (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:23:31)</span>
<span class="pl-c1">    at Object.lbd2 (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:42120:36)</span>
<span class="pl-c1">    at __webpack_require__ (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:23:31)</span>
<span class="pl-c1">    at Module.ILaR (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:15153:18)</span>
<span class="pl-c1">    at __webpack_require__ (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:23:31)</span>
<span class="pl-c1">    at /Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:91:18</span>
<span class="pl-c1">    at Object.&lt;anonymous&gt; (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:94:10)</span>
<span class="pl-c1">error Command failed with exit code 1.</span>
<span class="pl-c1">info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.</span>
</pre></div>
<h2 dir="auto">To Reproduce</h2>
<ol dir="auto">
<li>Go to '<a href="https://github.com/bokuo-okubo/next-with-ant-design-less-failed">https://github.com/bokuo-okubo/next-with-ant-design-less-failed</a>'</li>
<li><code class="notranslate">yarn</code></li>
<li>next =&gt; working fine</li>
<li>next build =&gt; Error</li>
</ol>
<p dir="auto">(also in the case remove <code class="notranslate">target: 'serverless'</code> flag, build works fine.)</p>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto">I tried to build with the check condition also options.dev flag, it works fine.</p>
<p dir="auto"><a href="https://github.com/bokuo-okubo/next-with-ant-design-less-failed/blob/4ceee6c40d3a3e52ef52407715b3a056c03f9605/next.config.js#L34">https://github.com/bokuo-okubo/next-with-ant-design-less-failed/blob/4ceee6c40d3a3e52ef52407715b3a056c03f9605/next.config.js#L34</a></p>
<p dir="auto">In the case of  using <code class="notranslate">target: 'serverless'</code> mode,  <code class="notranslate">config.externals</code> contain the <code class="notranslate">amp-toolbox-optimizer</code>, so the something wrong around there.</p>
<h2 dir="auto">Screenshots</h2>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/6664709/62014476-6102b680-b1dc-11e9-8e4f-5df01453f132.png"><img src="https://user-images.githubusercontent.com/6664709/62014476-6102b680-b1dc-11e9-8e4f-5df01453f132.png" alt="Screenshot 2019-07-29 08 37 21" style="max-width: 100%;"></a></p>
<hr>
<ul dir="auto">
<li>dump the option in the build time<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/6664709/62008025-a220a980-b18f-11e9-9845-f3f6de7f2932.png"><img src="https://user-images.githubusercontent.com/6664709/62008025-a220a980-b18f-11e9-9845-f3f6de7f2932.png" alt="" style="max-width: 100%;"></a></li>
</ul>
<h2 dir="auto">System information</h2>
<ul dir="auto">
<li>OS: macOS, Mojave, Version 10.14.5</li>
<li>Browser (if applies) [e.g. chrome, safari]</li>
<li>next version: "9.0.2"</li>
<li>package.json
<ul dir="auto">
<li>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;name&quot;: &quot;next-with-ant-design-less-failed&quot;,
  &quot;version&quot;: &quot;0.1.0&quot;,
  &quot;private&quot;: true,
  &quot;scripts&quot;: {
    &quot;dev&quot;: &quot;node server.js&quot;,
    &quot;build&quot;: &quot;next build&quot;,
    &quot;start&quot;: &quot;cross-env NODE_ENV=production node server.js&quot;
  },
  &quot;dependencies&quot;: {
    &quot;antd&quot;: &quot;^3.20.7&quot;,
    &quot;babel-plugin-import&quot;: &quot;^1.12.0&quot;,
    &quot;cross-env&quot;: &quot;^5.2.0&quot;,
    &quot;css-animation&quot;: &quot;^1.6.0&quot;,
    &quot;express&quot;: &quot;^4.17.1&quot;,
    &quot;less&quot;: &quot;^3.9.0&quot;,
    &quot;less-vars-to-js&quot;: &quot;^1.3.0&quot;,
    &quot;next&quot;: &quot;9.0.2&quot;,
    &quot;react&quot;: &quot;16.8.6&quot;,
    &quot;react-dom&quot;: &quot;16.8.6&quot;
  },
  &quot;resolutions&quot;: {
    &quot;css-animation&quot;: &quot;1.5.0&quot;
  },
  &quot;devDependencies&quot;: {
    &quot;@zeit/next-less&quot;: &quot;^1.0.1&quot;,
    &quot;null-loader&quot;: &quot;^3.0.0&quot;,
    &quot;style-loader&quot;: &quot;^0.23.1&quot;
  }
}"><pre class="notranslate">{
  <span class="pl-ent">"name"</span>: <span class="pl-s"><span class="pl-pds">"</span>next-with-ant-design-less-failed<span class="pl-pds">"</span></span>,
  <span class="pl-ent">"version"</span>: <span class="pl-s"><span class="pl-pds">"</span>0.1.0<span class="pl-pds">"</span></span>,
  <span class="pl-ent">"private"</span>: <span class="pl-c1">true</span>,
  <span class="pl-ent">"scripts"</span>: {
    <span class="pl-ent">"dev"</span>: <span class="pl-s"><span class="pl-pds">"</span>node server.js<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"build"</span>: <span class="pl-s"><span class="pl-pds">"</span>next build<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"start"</span>: <span class="pl-s"><span class="pl-pds">"</span>cross-env NODE_ENV=production node server.js<span class="pl-pds">"</span></span>
  },
  <span class="pl-ent">"dependencies"</span>: {
    <span class="pl-ent">"antd"</span>: <span class="pl-s"><span class="pl-pds">"</span>^3.20.7<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"babel-plugin-import"</span>: <span class="pl-s"><span class="pl-pds">"</span>^1.12.0<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"cross-env"</span>: <span class="pl-s"><span class="pl-pds">"</span>^5.2.0<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"css-animation"</span>: <span class="pl-s"><span class="pl-pds">"</span>^1.6.0<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"express"</span>: <span class="pl-s"><span class="pl-pds">"</span>^4.17.1<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"less"</span>: <span class="pl-s"><span class="pl-pds">"</span>^3.9.0<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"less-vars-to-js"</span>: <span class="pl-s"><span class="pl-pds">"</span>^1.3.0<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"next"</span>: <span class="pl-s"><span class="pl-pds">"</span>9.0.2<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"react"</span>: <span class="pl-s"><span class="pl-pds">"</span>16.8.6<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"react-dom"</span>: <span class="pl-s"><span class="pl-pds">"</span>16.8.6<span class="pl-pds">"</span></span>
  },
  <span class="pl-ent">"resolutions"</span>: {
    <span class="pl-ent">"css-animation"</span>: <span class="pl-s"><span class="pl-pds">"</span>1.5.0<span class="pl-pds">"</span></span>
  },
  <span class="pl-ent">"devDependencies"</span>: {
    <span class="pl-ent">"@zeit/next-less"</span>: <span class="pl-s"><span class="pl-pds">"</span>^1.0.1<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"null-loader"</span>: <span class="pl-s"><span class="pl-pds">"</span>^3.0.0<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"style-loader"</span>: <span class="pl-s"><span class="pl-pds">"</span>^0.23.1<span class="pl-pds">"</span></span>
  }
}</pre></div>
</li>
</ul>
</li>
</ul>
<h2 dir="auto">Additional context</h2>
<p dir="auto">Add any other context about the problem here.</p>