<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>
<h2 dir="auto">Expected Behavior</h2>


<p dir="auto">Assuming I've assigned an instance of next to the variable <code class="notranslate">app</code> and called <code class="notranslate">app.prepare()</code>, calling <code class="notranslate">app.close()</code> should stop all middleware and allow the Node process to exit.</p>
<h2 dir="auto">Current Behavior</h2>


<p dir="auto">In dev mode, the Node process keeps running with some middleware remaining active.  If a page was recently accessed, the "Disposing active pages" message will eventually be logged after <code class="notranslate">app.close()</code> was called, indicating that something has not stopped.  It will not stop after disposing pages either.</p>
<p dir="auto">When not running in dev mode, the Node process will exit as expected.</p>
<h2 dir="auto">Steps to Reproduce (for bugs)</h2>


<ol dir="auto">
<li>Follow the basic setup instructions, then create the following <code class="notranslate">server.js</code>:</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const path = require('path');

const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev, dir: path.resolve(__dirname) })
const handle = app.getRequestHandler()

app.prepare().then(() =&gt; {
  const http = createServer((req, res) =&gt; {
    const { parsedUrl } = parse(req.url, true)
    handle(req, res, parsedUrl)
      .then(() =&gt; http.close())
      .then(() =&gt; app.close())
  })

  http.listen(8080)
})"><pre class="notranslate"><code class="notranslate">const path = require('path');

const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev, dir: path.resolve(__dirname) })
const handle = app.getRequestHandler()

app.prepare().then(() =&gt; {
  const http = createServer((req, res) =&gt; {
    const { parsedUrl } = parse(req.url, true)
    handle(req, res, parsedUrl)
      .then(() =&gt; http.close())
      .then(() =&gt; app.close())
  })

  http.listen(8080)
})
</code></pre></div>
<ol start="2" dir="auto">
<li>
<p dir="auto">Build with <code class="notranslate">npm run build</code></p>
</li>
<li>
<p dir="auto">Run <code class="notranslate">node server.js</code> and point browser at app.  The Node process will NOT exit after request is handled.  Must Ctrl-C to exit.</p>
</li>
<li>
<p dir="auto">Run <code class="notranslate">NODE_ENV=production node server.js</code> and point browser at app.  The Node process will exit after request is handled.</p>
</li>
</ol>
<h2 dir="auto">Context</h2>


<p dir="auto">Came across this while working on a monitoring app to start/discover/stop instances of a Next app.  Instances wouldn't exit when told to via a <code class="notranslate">/stop</code> http request.</p>
<h2 dir="auto">Your Environment</h2>

<table role="table">
<thead>
<tr>
<th>Tech</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<tr>
<td>next</td>
<td>3.0.1-beta.13</td>
</tr>
<tr>
<td>node</td>
<td>7.10.0</td>
</tr>
<tr>
<td>OS</td>
<td>Ubuntu 14.04.5 LTS</td>
</tr>
<tr>
<td>browser</td>
<td>Chrome</td>
</tr>
</tbody>
</table>
<p dir="auto">Hello everyone,</p>
<p dir="auto">It seems @ types/next/router is missing an exported member called 'withRouter'. Is it a knowing issue?<br>
Any workaround for this?</p>
<p dir="auto">Thanks</p>


<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>
<h2 dir="auto">Your Environment</h2>

<table role="table">
<thead>
<tr>
<th>Tech</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<tr>
<td>next</td>
<td>4.1.4</td>
</tr>
<tr>
<td>node</td>
<td>8.5.0</td>
</tr>
<tr>
<td>OS</td>
<td>Windows 10</td>
</tr>
<tr>
<td>@ types/next</td>
<td>2.4.5</td>
</tr>
</tbody>
</table>